0

I'm trying to implement a jQuery slider that's bound to a select box as part of a questionnaire I'm putting together. However, I'm getting an Uncaught SyntaxError in Chrome and Expected ')' error in IE.

The jQuery I'm using is as follows and is a straight copy from the jQuery UI site found here:

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript">
  $(function() {
    var select = $( ".minbeds" );
    var slider = $( "<div id="slider"></div>" ).insertAfter( select ).slider({
      min: 1,
      max: 4,
      range: "min",
      value: select[ 0 ].selectedIndex + 1,
      slide: function( event, ui ) {
        select[ 0 ].selectedIndex = ui.value - 1;
      }
    });

    $( ".minbeds" ).change(function() {
      slider.slider( "value", this.selectedIndex + 1 );
    });
  });
</script>

Only change I've made to the code is that I've changed the #minbeds from and ID to a class (.minbeds).

The HTML is as follows:

    <select class="minbeds">
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
    </select>

Now, the code seems to work fine, with no errors on my local machine, but as soon as I put it into a CMS, I get an Uncaught SyntaxError: Unexpected Identifier error between the following lines (in chrome):

var slider = $( "<div id="slider"></div>" ).insertAfter( select ).slider({

and

min: 1,

In IE9, I get Expected ')' where the asterix indicates here:

var slider = $( "<div id="*slider"></div>" ).insertAfter( select ).slider({

Does anyone have any idea why this might be happening? Any thoughts on how I can narrow down the error? I've tried using JSLint, but I have no idea how to use it properly.

Here is the full source code for the CMS if it helps:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="head"><title>
test | Gael Ltd
</title><meta charset="UTF-8" /> 
<link href="/CMSPages/GetCSS.aspx?stylesheetname=GaelCorporate" type="text/css" rel="stylesheet" /> 
<link href="/App_Themes/Default/DesignMode.css" type="text/css" rel="stylesheet" /> 
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript">
  $(function() {

    var select = $( ".minbeds" );
    var slider = $( "<div id="slider"></div>" ).insertAfter( select ).slider({
      min: 1,
      max: 4,
      range: "min",
      value: select[ 0 ].selectedIndex + 1,
      slide: function( event, ui ) {
        select[ 0 ].selectedIndex = ui.value - 1;
      }
    });
    $( ".minbeds" ).change(function() {
      slider.slider( "value", this.selectedIndex + 1 );
    });
  });
</script> 
<link href="/favicon.ico" type="image/x-icon" rel="shortcut icon" /> 
<link href="/favicon.ico" type="image/x-icon" rel="icon" /> 
<link href="/App_Themes/GaelCorporate/site_superfish.css" type="text/css" rel="stylesheet" />
<link href="/App_Themes/GaelCorporate/superfish.css" type="text/css" rel="stylesheet" />
</head>

<body class="LTR IE IE9 ENGB ContentBody">
<form method="post" action="/test-folder/test.aspx" id="form">

<div class="aspNetHidden">
  <input type="hidden" name="manScript_HiddenField" id="manScript_HiddenField" value="" />
  <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
  <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
</div>

<script type="text/javascript">
//<![CDATA[
  var theForm = document.forms['form'];
  if (!theForm) {
      theForm = document.form;
  }
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>


<script src="/WebResource.axd?d=jPoMVS0EaQHOPmIi_xm2HU7yLiOSI9SwD_nAvxdPGg3slCV5HIxf7PSCa8BfM4b35NfjJ4LD1KDvV9zGMhi-uyAc4R1j13kmLSk37dPSwRA1&amp;t=635080272185083230" type="text/javascript"></script>

<input type="hidden" name="lng" id="lng" value="en-GB" /><div>
<input type="hidden" name="vmode" id="vmode" value="2" />
</div>

<script src="/CMSPages/GetResource.ashx?scriptfile=%7e%2fCMSScripts%2fcmsedit.js" type="text/javascript"></script>
<script src="/ScriptResource.axd?d=qITU4oF4GWOpdURxveOn4klAk_JXip46ZHYKRqOUaPkNBV9OLAT0zMmPuZjF0ltSZKQlH5lCAk6I-L0CB4BfF84f5lbs5uiDmHRHcZEufPBw7X-M84RuYSjEXgjwE-gx0&amp;t=34d147fd" type="text/javascript"></script>
<script src="/ScriptResource.axd?d=05xl_ew97J9D2HSa4Uccwf9-hvRXKd018osO5VbhpBA71UbuP-EbmT7rx4i0SCEzVoF8fX63gNR8y-mVT88Ca0QEYuqmsHW4GGpDjGvljtfyIoQXInytcQQGxUI7XAD5x4baeNOY1cVoynUnafwICw2&amp;t=34d147fd" type="text/javascript"></script>

<div class="aspNetHidden">
<input type="hidden" name="__SCROLLPOSITIONX" id="__SCROLLPOSITIONX" value="0" />
<input type="hidden" name="__SCROLLPOSITIONY" id="__SCROLLPOSITIONY" value="0" />
</div>

<script type="text/javascript">
//<![CDATA[
  Sys.WebForms.PageRequestManager._initialize('manScript', 'form', [], [], [], 90, '');
//]]>
</script>

<div id="m" style="background:none;">
<div id="CMSHeaderDiv">
    <div id="m_PageManagerInfoContainer" class="PageManagerInfoContainer">
        <!-- --><div id="m_pnlPreviewInfo" class="PageManagerPreviewInfo">
            <span class="PreviewInfo">This is a preview mode of document <strong>test</strong>.</span><a class="PreviewInfoLink" href="javascript:__doPostBack(&#39;m$ctl02&#39;,&#39;&#39;)">Close</a><span class="PreviewInfo">the preview mode.</span>
            </div>
    </div>

<script type="text/javascript">
    //<![CDATA[
    if ( (parent != null) && (parent.IsCMSDesk) ) { infoElem = document.getElementById('m_pnlPreviewInfo'); if (infoElem) {if ( infoElem.style ) { infoElem.style.display = 'none'; } else { infoElem.display = 'none'; } }}
//]]>
</script><!-- -->
</div>
</div>

<div id="pagewrapper">
  <!-- vertical_menu div start -->
<div id="vertical_menu">


</div><!-- vertical_menu div end -->

<!-- content_container div start -->
<div id="content_container">
<div id="zoneContent">
    <div id="p_lt_zoneContent_BizForm_viewBiz">
<div id="p_lt_zoneContent_BizForm_viewBiz_ctl00">
    <div id="p_lt_zoneContent_BizForm_viewBiz_ctl00_pnlForm" class="FormPanel" onkeypress="javascript:return WebForm_FireDefaultButton(event, &#39;p_lt_zoneContent_BizForm_viewBiz_ctl00_btnOK&#39;)">
        <table class="EditingFormTable"><tr><td class="EditingFormLabelCell"><label id="p_lt_zoneContent_BizForm_viewBiz_ctl00_select_lb" class="EditingFormLabel" for="p_lt_zoneContent_BizForm_viewBiz_ctl00_select_dropDownList">select field</label></td><td class="EditingFormValueCell"><div class="EditingFormControlNestedControl">

<select name="p$lt$zoneContent$BizForm$viewBiz$ctl00$select$dropDownList" id="p_lt_zoneContent_BizForm_viewBiz_ctl00_select_dropDownList" class="minbeds">
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
</select>

</div></td></tr><tr>

<td class="EditingFormButtonLeftCell"></td>
<td class="EditingFormButtonCell">
    <input type="submit" name="p$lt$zoneContent$BizForm$viewBiz$ctl00$btnOK" value="OK" id="p_lt_zoneContent_BizForm_viewBiz_ctl00_btnOK" class="FormButton" />
  </td></tr></table>
  </div>
</div>
</div>

<select name="minbeds" class="selectInput">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
</select>
</div>

<div class="bottomWebParts"></div>

</div>
<!-- content_container div end -->

<!-- primary webparts div start -->
<div id="primary_webparts"></div>

<!-- primary webparts div end -->
</div>

<script type="text/javascript">
//<![CDATA[
  (function() {var fn = function() {$get("manScript_HiddenField").value = '';Sys.Application.remove_init(fn);};Sys.Application.add_init(fn);})();//]]>
</script>

<script type="text/javascript">
  //<![CDATA[
   InitializePage();
  //]]>
</script>

<script type="text/javascript">
  //<![CDATA[
    theForm.oldSubmit = theForm.submit;
    theForm.submit = WebForm_SaveScrollPositionSubmit;

    theForm.oldOnSubmit = theForm.onsubmit;
    theForm.onsubmit = WebForm_SaveScrollPositionOnSubmit;
  //]]>
</script>

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTYwODg0MzQ2Ng9kFgICARBkZBYCAgMPZBYCZg9kFgJmD2QWAgIDD2QWAmYPZBYCZg8PFgIeCEZvcm1Nb2RlCyl1Q01TLkZvcm1FbmdpbmUuRm9ybU1vZGVFbnVtLCBDTVMuRm9ybUVuZ2luZSwgVmVyc2lvbj02LjAuNDcxMy4yNzkyNiwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj04MzRiMTJhMjU4ZjIxM2Y5AGQWAgICD2QWAmYPZBYEAgEPDxYCHgdWaXNpYmxlaGQWAgIBDw8WBB4IQ3NzQ2xhc3MFH0VkaXRpbmdGb3JtQ29udHJvbE5lc3RlZENvbnRyb2weBF8hU0ICAmQWAmYPZBYCZg8PFgQfAgUKTGFiZWxGaWVsZB8DAgJkZAIHD2QWAgIBDw8WBB8CBR9FZGl0aW5nRm9ybUNvbnRyb2xOZXN0ZWRDb250cm9sHwMCAmQWAmYPDxYCHwJkZBYCZg8QDxYEHwIFB21pbmJlZHMfAwICZA8WBGYCAQICAgMWBBAFATEFATFnEAUBMgUBMmcQBQEzBQEzZxAFATQFATRnZGRkpyri0ouEXB8y3l0reZFw/5xfESlKtjr/PsCd4HT+bG4=" />
<script type="text/javascript"> 
  //<![CDATA[
  if (window.WebForm_InitCallback) { 
    __theFormPostData = '';
    __theFormPostCollection = new Array();
    window.WebForm_InitCallback(); 
  }
  //]]>
</script>
</form>

</body>
</html>

2 Answers 2

2

Try like

var slider = $( "<div id='*slider'></div>" ).insertAfter( select ).slider({

or directly you can do like

var slider = $( "div #slider" ).insertAfter( select ).slider({

and I think you need to put select in single or double quotes.

Sign up to request clarification or add additional context in comments.

Comments

1

Try this

var slider = $( '<div id="slider"></div>' ).insertAfter( select ).slider({

2 Comments

This worked, thanks! Any idea why the initial code worked on my local machine and not online?
not exactly, but whenever there is a string inside a string it's better to put like this ' " " ', browser won't throw parsing error... see here w3.org/TR/css3-values/#component-types

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.