• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaScript runtime error

 
Sat Kum
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a function in my JSP and am calling it when the user clicks on an image.

I get a runtime error
"Unterminated string constant"
I tried all possibilities like using escape characters, removing double quotes ..etc.
do anyone have an answer..?
[ July 16, 2002: Message edited by: Sathish ]
 
Yuriy Fuksenko
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
in your example single quote, right before "javascript:" closed inside word Provider'2
And if you use onclick, you don't need "javascript:".
<img src="../images/edit_button.gif" border="0"
on_click='OnClickEdit("SunLife","Provider\'2","909090909");'>....
 
Sat Kum
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
What if the the single quote's position in the string varies dynamically..?
Sathish
 
Randall Twede
Ranch Hand
Posts: 4371
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sathish
i agree with what Yuriy said. also, i thought single quotes were used inside double quotes. i dont see any double quotes enclosing the single quotes. otherwise Yuriy's code looks right to me(it's been a while but i seem to recall using \ to escape special chars). semicolon at end is not needed either although it is allowed.

<img src="../images/edit_button.gif" border="0"
on_click="OnClickEdit('SunLife','Provider\'2','909090909')">....

I hate to say this but, your name does not comply with the Javaranch naming guidelines which can be found at http://www.javaranch.com/name.jsp
please register again with a valid name.
[ July 17, 2002: Message edited by: Randall Twede ]
 
Randall Twede
Ranch Hand
Posts: 4371
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if single quote position varies dynamically, i think you are out of luck. it has a meaning to html and must be escaped to not be interpreted.
 
Yuriy Fuksenko
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
look at this thread http://www.coderanch.com/t/113011/HTML-JavaScript/Check-special-characters
It looks simular to your question.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic