Vivek Thakur

Chaotically Complex

  Home  |   Contact  |   Syndication    |   Login
  105 Posts | 1 Stories | 502 Comments | 65 Trackbacks

News



Archives

ASP.NET Ventures

*******************
Note: view the updated entry below:

http://www.codeasp.net/blogs/vivek_iit/microsoft.net/130/error-using-single-quote-in-javascript

*******************

A junior developer in our recent project got stuck in this issue: he had to call Javascript code from VB.NET  code behind and insert this value in a function: Jammin' Hard.

Now the single quote (apostrophe ') was creating trouble, giving an error as JS string got terminated. A simple solution in such cases is to use HTML codes for apostrophe, which is : '
So the string should be passed as: Jammin' Hard

This solved his issue. See this table for more codes: http://www.netlingo.com/tags.cfm
posted on Wednesday, January 23, 2008 2:07 AM

Feedback

# re: Error using single quote in Javascript 1/23/2008 5:40 AM Andrew
You could also, instead of using single quotes to delimit your strings, use double quotes and then you don't need to delimit your apostrophe's, ie:

"jammin' hard" instead of 'jamin' hard'



# re: Error using single quote in Javascript 3/24/2008 12:23 PM imicomputer
another way to write a quote is using an escape string (\).
ie:

Jammin' Hard --> Jammin\' Hard

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: