Link to home
Start Free TrialLog in
Avatar of HumbleBeginnings
HumbleBeginningsFlag for United States of America

asked on

Apparent collision of square brackets in jQuery and Classic ASP

Hello Everyone,

I am not an ASP guru and I am writing some code in Classic ASP and trying to introduce jQuery. Most things work well, however I have a problem with square brackets messing with what I presume to be the ASP parser. Typically functions are called in brackets like [ADD_PAGEHEADER] or [ADD_FORMSTART]. The problem seems to be the brackets in the jQuery script (below) are trying to be interpreted by the ASP parser, I think.

<script>
      $('input[name=FeatureList]').change(function() {
            $("#cb").append("this is a test");
      });  
</script>

The script fails at the point where the jQuery script begins in an ASP processed page, but works fine in straight HTML. In the script jQuery above, radio buttons seem to be handled a little differently than many other form elements and the syntax is a little quirky.

Is there anyway to turn off the ASP parser during the running of this script or maybe some other workaround to the apparent collision of the brackets? I tried escaping out the brackets but that didn't work either.

Thanks in advance for your help.

HB
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think it should be

 $("#FeatureList").change(function() { 
            $("#cb").append("this is a test");
      });  

Open in new window

or something like:

 
$("input[type='checkbox'][name='FeatureList']").change(function() { 
            $("#cb").append("this is a test");
      });  

Open in new window


or

 
$("input:checkbox[name='FeatureList']").change(function() { 
            $("#cb").append("this is a test");
      });  

Open in new window

Actually this should work fine:

 $('input[name="FeatureList"]').change(function() { 
            $("#cb").append("this is a test");
      });  

Open in new window

Which is what I posted
to be fair, you posted

 $("input[name='FeatureList']")

and I posted

$('input[name="FeatureList"]')
and while yours modified the author's code, mine was simply wrapping FeatureList in double quotes
Whether one type of quotes are used on the inside as opposed to the outside makes no functional difference. You just have to make sure that you escape any that need escaping (which is not needed in this example).

I think it should be
$("#FeatureList")
An ID and a name are not the same. An ID must be unique, where as, especially with radio button groups, multiple form controls may have the same name.
@YZlat: And this large amounts of unnecessary postings results in what? That we agree that the quotes are the issue?
I added the quotes to the selector - irrelevant which way the quotes are added as long as they are there. I modified them to my preference.
That does not make it less correct than a suggestion where I left the original quotes in place.

I agree with Kravimir - $("#...") is for ID and not for NAME. I did not want to pollute the question with even more posts so I did not mention it
mplungjan, talking about polluting the post...