Solved

Apparent collision of square brackets in jQuery and Classic ASP

Posted on 2012-04-10
12
28 Views
Last Modified: 2016-04-24
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
0
Comment
Question by:HumbleBeginnings
  • 6
  • 3
12 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 37832034
I would expect

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

http://api.jquery.com/attribute-equals-selector/
0
 
LVL 35

Expert Comment

by:YZlat
ID: 37832273
I think it should be

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

Open in new window

0
 
LVL 35

Expert Comment

by:YZlat
ID: 37832291
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

0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 35

Expert Comment

by:YZlat
ID: 37832304
Actually this should work fine:

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

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37832445
Which is what I posted
0
 
LVL 35

Expert Comment

by:YZlat
ID: 37832641
to be fair, you posted

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

and I posted

$('input[name="FeatureList"]')
0
 
LVL 35

Expert Comment

by:YZlat
ID: 37832645
and while yours modified the author's code, mine was simply wrapping FeatureList in double quotes
0
 
LVL 42

Expert Comment

by:David S.
ID: 37832681
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.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37832691
@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
0
 
LVL 35

Expert Comment

by:YZlat
ID: 37832981
mplungjan, talking about polluting the post...
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question