?
Solved

Double quotes not showing up in textbox

Posted on 2006-10-30
3
Medium Priority
?
663 Views
Last Modified: 2012-08-14
I have a textbox that a user can type in anything.  If the user uses double quotes it save it fine.  When the page is brought up again anything past the double quotes is missing.  It is saved in the DB but is not shown in the textbox.  I created a hidden field and when I view source everything is there but when I change the hidden field to a textbox everything past the double quotes is missing.  Why is this and how do I prevent it from happening?
0
Comment
Question by:huerita37
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 53

Assisted Solution

by:Ryan Chong
Ryan Chong earned 400 total points
ID: 17839421
try use server.HTMLEncode function to encode the characters? try like:

<input name="co_name" type="text" id="co_name" value="<%=server.HTMLEncode("" & rs("co_name"))%>" size="54" maxlength="100">
0
 

Author Comment

by:huerita37
ID: 17839463
That worked but why do you need to do that?
0
 
LVL 25

Accepted Solution

by:
Lee Savidge earned 600 total points
ID: 17840814
Hi,

The reason it worked is because the double quote character is a string delimiter in HTML. So when ASP displays the double quotes it renders it as the actual character rather than encoding it. So, for example, you have this string in a tex box:

Bob says "hi"!

You save it, everythnig is good. When the code is read back from the database it is displayed in the text box. The HTML code will receive this:

<input name="co_name" type="text" id="co_name" value="Bob says "hi"!" size="54" maxlength="100">

So, the value attribute has an oipening double quote and the string starts displaying. The string ends when it receives the second double quote. In this example, the second double quote is just before the bit that says hi. This means the string in the attribute is "Bob says " and anything afterwards is ignored which is what you're experiencing. To cure this problem you need to escape the string delimiter characters inside the text string so that the 2 double quote in my example aren't treated as string delimiters, rather they are treated as characters in the string. This is why you use the server.HTMLEncode function. What this does is covert the string within the value attribute into "safe" HTML. In this example the string is converted to:

Bob says &quot;hi&quot;!

the &quot; is what replaces the 2 double quotes. These are the HTML character codes for the double quote character. This means that when the browser renders the string, the opening double quote begins things. The string the writes to the screen, but when the browser sees the &quot; it displays a double quote and doesn't delimit the string. The string ccontinues displaying and does the same or the second &quot;. It continues until it hits the final double quote at the end of the string. This means that your string displays correctly and the browser has done it's job and everyone is happy. See http://windowssdk.msdn.microsoft.com/en-us/library/ms525347.aspx for more info. There are also HTMLDecode, URLEncode and URLDecode functions that encode and decode things for different reasons.

Regards,

Lee
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question