Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem Displaying Double Quotes in TextBox

Status
Not open for further replies.

bper123

Programmer
Jan 24, 2006
10
US
Hi,

I've searched the forum and the FAQs and haven't found this topic.

I have html forms which accept user data. The textboxes will not accept double quotes. The behavior that I see consistently is that the double quote and any characters following it will be truncated. Sometimes, although it is not consistent, the subsequent forms are distorted. The fields are displayed all over the screen. This is probably because of how the quotes are interpreted by the browser. This problem does not occur in textareas.

Is there a script that will handle quotes and other special characters in text fields?
 
Hi, and thanks for your reply.

I have tried " before and that works of course. But my question, I guess, is do I have to parse each text field for a quote and replace it with " before displaying in a textbox? Would I have to do this for every textbox? And if so, what's the best way to do this? In JavaScript or on the server side?

Thanks again.
 
The textboxes will not accept double quotes.
do I have to parse each text field for a quote and replace it with " before displaying in a textbox?
What problem are you having? Is it that quotes the end-users enter in textboxes are lost/garbled before they get to whatever your form does?

Or is it that you're outputting a form with pre-populated values, and that you have problems when those values include quotes?

The first seems very unlikely, with any fault probably lying in your server-side form handling script.

The latter will certainly cause problems, how do you expect browsers to understand this?:
Code:
<input name="xxx" value="this bit is ok " this isn't!">
It can't tell the difference between a " in the value, and the " that ends the value string. You've already come up with the solution - parse the string for " (and & and <, while you're at it) and replace with &quot; (&amp; and &lt;) when producing your HTML. And do it server side so it always happens.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Yes, the latter is of course the problem. Thanks for your help. I'll do it on the server side.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top