Solved

Apparent collision of square brackets in jQuery and Classic ASP

Posted on 2012-04-10
12
25 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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now