aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes Special characters in  input text value Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Special characters in  input text value" Watch "Special characters in  input text value" New topic
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
    
  13

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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Special characters in input text value
 
Similar Threads
Disabling a text field leads to loss of value
Reading the XML file using DOM
JTextField.setEditable is not working
How to align text to RIGHT in h:outputText
Drop Down List