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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange Textbox behavior - apostrophes limit text shown 1

Status
Not open for further replies.

Trusts

Programmer
Feb 23, 2005
268
US
Hi all,

I have a query from a mySQL database. The results are fed into a form (the form is made on the fly with PHP).

If a string has an apostrophe (a single quote mark), the text stops at that point.

For example, John's Hardware Store becomes John

Is there a trick or function to get around this?

Thanks,
KB
 
Yes, It happens because when you output the string with an apostrophe the browser can't tell where the value of the input is supposed to end. Taking from your example, you output the string into a textbox:
Code:
<input type=text value='John's Hardware Store'>

The browser gets as far as John, and then finds a quote. It thinks thats the end of the string for the value. And takes the rest as aditional attributes of the input type.

You can do 2 things, either use [blue]htmlentities()[/blue] to prepare your output before hand, or change the quotes of your from from, single to double.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks, I reversed the double and single quotes and all works fine now.
 
although you will have the same problem if your user includes double quotes inside the text box (e.g. a House name: "Dunroamin").

better to use htmlentitites().
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top