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

How to keep single quotes in text?

Status
Not open for further replies.

Chopstik

Technical User
Oct 24, 2001
2,180
US
I have created several text boxes that allow for user input and the variables can then be carried to following pages, but have discovered that if they use single quotes (i.e. - Sam's Club), it cuts off at the single quote. Is there a way around this so that it will keep the single quotes? Thanks!
 
The string is cut only when you use this in Javascript functions.
When you read by Request.form and request.querystring it should come to the next page complete.
For Javascript I use this function to format the string

Function FormatStringForJavaScript( vString )
Dim sTemp
sTemp = vString
If Not IsNull(sTemp) Then
sTemp = Replace(STemp, "\", "\\")
sTemp = Replace(sTemp, "'", "\'")
sTemp = Replace(sTemp, """", "\""")
sTemp = Replace(sTemp, chr(10), "\n")
sTemp = Replace(sTemp, chr(13), "\r")
End If
FormatStringForJavaScript = sTemp
End Function

BUT, if you use
<input type=text value='Sam's club'> it's cuting the value so try to use double quotes on the value like this
<input type=text value=&quot;Sam's club&quot;>

regards,
durug
 
You could do
Code:
   Server.HTMLEncode(string)

or if you just want to convert the single quotes:
Code:
   string = Replace(string, &quot;'&quot;, &quot;& #39;&quot;)

PS
Remove the space between & and #
I had to put it there to bypass the parser at Tek-Tips. :)
DS

Hope this helps,
Palooka
 
Thanks, people. That helped a lot. I was using the input type and ended up writing the following: (keep in mind that this is also iterated, ergo the &quot;i&quot;)

Response.Write &quot;<td>&quot; & server.HTMLEncode(Request.form(&quot;strVenItemCd&quot; & i)) & &quot;</td>&quot;

That seems to have taken care of the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top