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

Posting textbox values

Status
Not open for further replies.

mainmast

Programmer
Jun 26, 2003
176
US
Hi all,

When I enter data into my database I replace single quotations with doubles (e.g: " to "" and ' to ''). Then when I want to post it back out to the user I replace double quotations with singles (e.g: "" to " and '' to ').

However when I input these into text box values if the string contains a quotation it prematurely ends the value attribute.

Code:
strToCheck = Replace(strToCheck, """", """""") ' This is my code to replace single quotations to doubles when entering it into database

strToCheck = Replace(strToCheck, """""", """") ' This is my code to replace double quotations to singles when displaying it in the browser

Then when I want to show the variable in a textbox the string gets cut short. (If I have this string: 'He said, "Hi!"', it'll only show: 'He said, '). This is the code for this:

Code:
<input type="text" name="FineAmount" style="Width: 90%;" value="<%=FineAmount%>">

FineAmount has already been through the replace statement to change double quotations to singles.

Any thoughts on how to post the string in its full length?
 
When pushing the data to the database you should only need to replace single quotes with two single quotes: ' => ''
Basically this is an escape character so that the SQL statement will not treat that single quote as the end of your string. it then inserts your string with one single quote.

So this means you do not need to replace two single quotes with one single quote when you return later to use the data. you also should not need to escape double quotes. The only time you need to escape double quotes by doubling them up is if your declaring a string in ASP that has double quotes in them. If they are already inside a variable then you don't need to because they already made it into the variable value.

Continue to replace " with &quot when you output data to into HTML elements, as mbiro pointed out, otherwise the browser will think it has reached the end of the value when it hits the first double quote and will ignore everything after it.

-T

Best MS KB Ever:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top