Solved

Double quotes not showing up in textbox

Posted on 2006-10-30
3
656 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
3 Comments
 
LVL 49

Assisted Solution

by:Ryan Chong
Ryan Chong earned 100 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 150 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
pass url parameter as session 9 40
Using AJAX to call classic ASP function 4 69
Grab data from remote page 10 57
CSS Question.. 3 72
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now