| Author |
JavaScript runtime error
|
Sat Kum
Greenhorn
Joined: Jul 16, 2002
Posts: 5
|
|
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
Joined: Feb 02, 2001
Posts: 413
|
|
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
Joined: Jul 16, 2002
Posts: 5
|
|
Hi, What if the the single quote's position in the string varies dynamically..? Sathish
|
 |
Randall Twede
Ranch Hand
Joined: Oct 21, 2000
Posts: 4095
|
|
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 ]
|
SCJP
|
 |
Randall Twede
Ranch Hand
Joined: Oct 21, 2000
Posts: 4095
|
|
|
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
Joined: Feb 02, 2001
Posts: 413
|
|
look at this thread http://www.coderanch.com/t/113011/HTML-JavaScript/Check-special-characters It looks simular to your question.
|
 |
 |
|
|
subject: JavaScript runtime error
|
|
|