View Full Version : text box only display up to first space
njk966
01-13-2003, 01:28 PM
I am filling out a text box and returning values back to the same form via a query string. The full value of the text box is being returned in the query string variable, but only displays up to the first space when inserting into the value field of the text box. I am using JavaScript and ASP.
(i.e. somevar=querystringvar
<input type=text value="&somevar&">"
"JavaScript is fun" would only display "Javascript" in the text box
although somevar="JavaScript is fun" )
codefox
01-13-2003, 03:30 PM
This works for me
<FORM METHOD=get ACTION="t1.asp">
<input name="somevar" type=text value="<%= Request.QueryString("somevar") %>">
<input type="submit">
</FORM>
njk966
01-13-2003, 06:14 PM
I have a condition where I use the same code to either display what I use from the query string or I use to display new data from a returned recordset.
Either way I update the same variable and use that variable to display my result.
I am able to update and Response.Write(SomeVar) and the correct data is written out, but when I assign that variable to a text box value it only gives me the first word.
njk966
01-13-2003, 07:42 PM
SomeVar = "Its only Rock n Roll"
Response.Write SomeVar ----->displays "Its only Rock n Roll"
Response.Write "<input TYPE=text value="&SomeVar&">"
------->displays "Its"
arnyinc
01-13-2003, 07:47 PM
Enclose the value in quotes. If you do a view source you will probably have something like the following so the value doesn't see the rest of that phrase:
<input type=text value=Its only rock and roll>
Make your source code:
response.write "<input type=""text"" value="""&somevar&""">"
njk966
01-13-2003, 10:21 PM
"Quotes are very useful when used", you can quote me on that!
whammy
01-13-2003, 11:57 PM
To further expand on that, you should always use Server.HTMLEncode when displaying values as well, at least in an editable field - otherwise people can break your HTML... i.e.:
Dim mytext
mytext = Request.Form("mytext")
If mytext = "" Then mytext = "It's only Rock & Roll!"
Response.Write("<input type=""text"" name=""mytext"" value=""" & Server.HTMLEncode(mytext) & """ />" & vbCrLf)
If you're not sure what I mean, request the value as above by posting the page to itself using the "post" method, and then type into the field:
<"" Hi, my name is Nick!
and submit it again... you'll see your HTML is broken.
:)
njk966
01-14-2003, 12:15 AM
Works like a charm. I will adhere to that advice from now on.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.