Computing.Net > Forums > Programming > Populating a text box with asp

Populating a text box with asp

Reply to Message Icon

Original Message
Name: adam
Date: December 13, 2003 at 03:37:00 Pacific
Subject: Populating a text box with asp
OS: win98/winXp/win2000
CPU/Ram: from 600/2000 - 128
Comment:

Hi, I'm making a website where you have to log in. It reads your information from a database and checks your password etc. When it has logged you in, you are taken to your account settings. Here you can specify if you want to change any details. You click the link, and it takes you to a page where your name, address (its an online shop) etc. are listed in textboxes using the code

<input type="text" name="txtSurname" value=<%=rs("Surname")%>>

where rs is the record set and Surname is the name of the field in the database. The problem is this works fine for one word fields, but if you want something with more than one word it wont show.

e.g. If your address is a string "47 Parkview Road" then only "47" will appear. If you check the variable that is being pulled out of the box and dispay it as html (albeit dynamic) then the full string "47 Parkview Road" is being pulled out. So it is definatley a problem with the text box.

Any solutions, if not anyone had the same problem and just found a way round it. Would love some help its one of those niggling little errors that really annoys you.

Thanks,
Adam


Report Offensive Message For Removal


Response Number 1
Name: scott
Date: December 13, 2003 at 11:20:54 Pacific
Reply: (edit)

well, The only thing plausible that i can think of is that you would need to encode the form values before you sumit them to the database. This just makes the information into a more computer-friendly form. In javascript this can be done with the escape object: escape(variable) *or* escape(string)
Before you display the information again though, use the unescape object:
unescape(variable) *or* unescape(string).
Doing all of this encoding will turn normal strings and stuff into ASCii values. Most importantly, as your problems suggests, it will turn a space into a %20. hope this helped.

-scott


Report Offensive Follow Up For Removal

Response Number 2
Name: Eitan-CyproX
Date: January 3, 2004 at 17:38:10 Pacific
Reply: (edit)

The problem is simple - quotation marks (")

The solution is simple as well.

Either of these will solve the problem:

<input type="text" name="txtSurname" value="<%=rs("Surname")%>">

Or

<%
Response.Write "<input type=""text"" name=""txtSurname"" value=""" & rs("Surname") & """>
%>

Hope this helps - Eitan


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Populating a text box with asp

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge