File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Escaping Single Quote (apostrophe ) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Escaping Single Quote (apostrophe )" Watch "Escaping Single Quote (apostrophe )" New topic
Author

Escaping Single Quote (apostrophe )

Sam Kumar
Ranch Hand

Joined: Nov 30, 2001
Posts: 38
Hi,
I am trying to escape single-quote but I am getting javascript error.
Here is the HTML:
<A HREF="javascript:submitForm('SINGLEQUOTE_TEST','Single'Quote');">SingleQuote-Escape Test</A>
<BR><BR>
<script language="javascript">
function submitForm(a, id){
alert(a);
alert(id);
}
</script>
On clicking the link, I am getting following error:
Line 1, Char 31, Expected ')'
Here actual string is
Single'Quote
and I am replacing single quote with ' i.e.
Single'Quote
Any ideas why I am getting javascript error!
Thanks in advance!
SK
Sam Kumar
Ranch Hand

Joined: Nov 30, 2001
Posts: 38
Oops javaranch replaced "'" with ' while posting. I am puting extra space to avoid conversion.
Here is the HTML:
<A HREF="javascript:submitForm('SINGLEQUOTE_TEST','Single& #039;'Quote');"> SingleQuote-Escape Test</A>
<BR><BR>
<script language="javascript">
function submitForm(a, id){
alert(a);
alert(id);
}
</script>
Here actual string is
Single'Quote
and I am replacing single quote with & # 039; ' i.e.
Single& # 039;Quote
(Ignore extra space)

Thanks in advance!
SK
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
the center apos is causeing the error in 'Single'Quote'
You can do it either
'Single\'Quote'
or
'Single'Quote'
Eric
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
<A HREF="javascript:submitForm('SINGLEQUOTE_TEST','Single&#039;'Quote');">
THis line still has the ' in it afer the &#039;
that is the reason why the error appears
 
IntelliJ Java IDE
 
subject: Escaping Single Quote (apostrophe )
 
Threads others viewed
Getting access is denied exception on IE
alert is not working
Trying to use AJAX to call a servlet
Java Script problem
Is there something better then event.pageX/Y?
developer file tools