?
Solved

Apparent collision of square brackets in jQuery and Classic ASP

Posted on 2012-04-10
12
Medium Priority
?
39 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
12 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 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
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

770 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