| Author |
Special characters in input text value
|
Jennifer Moran
Ranch Hand
Joined: Oct 21, 2002
Posts: 60
|
|
Hi, this is driving me bananas. I have a JSP page that queries the database. In the Javascrip initForm I am filling up the values of the various text boxes. Below is an example piece of code that blows me right out of the water if the BookBean.getShipper() value includes either a " or a ' . How do I get around this??? I am completely fine when I want to only display the value and then I do the whole encoding of the HTML (ex. if its a " then replace it with " etc.) But this does NOT work with a text box value!! Help!!! window.document.theForm.shipper.value = "<%=BookBean.getShipper()%>";
|
 |
Garann Means
Ranch Hand
Joined: Jan 28, 2002
Posts: 214
|
|
Hi Jennifer, I'm not sure if I'm following you, but if I am, your JavaScript could be blowing up because it doesn't see the a legal expression being assigned to that text box (maybe it sees something like: ...value = "My cat is "funny" looking."; and tries to read funny as an operator). If that's it, you can get around it pretty easily by setting your value in the form, instead of in JavaScript: <input type="text" name="shipper" value="<%=BookBean.getShipper()%>"> hth, g.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56221
|
|
Even setting the value on the server end will not completely solve the problem. You could end up with something like: which would confuse the browser no end. A fairly thorough solution is to set the value on the server end after replacing all instances of " with \". This should escape the quote character and keep the browser from tripping over them. hth, bear
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Jennifer Moran
Ranch Hand
Joined: Oct 21, 2002
Posts: 60
|
|
Thank you both very much...I used the replacement method and it looks good... Appreciate the help, Jennifer
|
 |
 |
|
|
subject: Special characters in input text value
|
|
|