...

View Full Version : Quotes In Dynamic Form



JoeP
02-17-2003, 03:25 AM
I'm trying to resolve my problem reading the above sticky posts where the forum offers scripts and tips about single quotes etc. But, I am still having a little problem

MSAcess 2000 SQl Statement

On a form I can Capture Field Data [strDescr]: Mr. Jone's "Bank"
On Update or Insert I have a similar function that takes care of replacing the (') in Mr. Jone's prior to updating the Table field.

When I write a dynamic form with response.write for subsequent editing and update... using SELECT
to pull out the record..e.g.

strDescr = rs("strDescr")

Response.write( "<input type='text' value='" & strDescr & "name='Description' size='50'>" )

On the new form I get output like below in the text box:

Description: Mr. Jone's &quot;Bank&quot;

Where It Should be; Mr. Jone's "Bank"

Would someone please set me straight on this one.

TIA

glenngv
02-17-2003, 08:47 AM
<%
strDescr = rs("strDescr")
Response.write( "<input type=""text"" value=""" & server.htmlencode(strDescr) & """ name=""Description"" size=""50"">")
%>

JoeP
02-17-2003, 02:06 PM
Thank you!

Ooops! When I tried this with: Mr. Jone's "Bank"

The output was:

Mr Jone’s &amp;quot;bank&amp;quot;:confused:

glenngv
02-18-2003, 08:50 AM
yes, but since you will output it inside the textbox or even as html text, it would be displayed/rendered correctly.

whammy
02-19-2003, 12:38 AM
Yeah, you shouldn't actually change the variable that you are requesting from the database or webpage using Server.HTMLEncode(). That will corrupt your data!

You only want to change it while you are displaying it in HTML with Server.HTMLEncode().

Try using Server.HTMLEncode() ONLY while you are printing the variable to the webpage... like:

<p><% Response.Write(Server.HTMLEncode("myvariable")) %></p>

Get it? :)

glenngv
02-20-2003, 02:56 AM
but if you are putting it in a javascript variable, you have to escape those characters according to javascript syntax:
see this thread: http://www.codingforums.com/showthread.php?s=&threadid=10513



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum