SitePoint Sponsor |
|
User Tag List
Results 1 to 15 of 15
Thread: Automatic Form Fill-in with ASP
-
Nov 7, 2001, 10:48 #1
- Join Date
- Jul 2001
- Location
- Houston
- Posts
- 130
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Automatic Form Fill-in with ASP
I'm doing a form in HTML that is automatically filled in for the customer, by way of hidden form fields on another page. I'm doing it like this:
Code:<input type="text" name="fname" value="<%= strFirstName %>">
Code:<select class="fielder" name="bill[state]"> <option value="AK">AK</option> <option value="AL">AL</option> <option value="AR">AR</option> ... <option value="WI">WI</option> <option value="WV">WV</option> <option value="WY">WY</option> </select>
Last edited by writhe; Nov 7, 2001 at 10:54.
-
Nov 7, 2001, 11:01 #2
- Join Date
- Feb 2001
- Location
- Clearwater, FL
- Posts
- 3,615
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
So, you want it automatically selected based on the user information, but the user can still select another state from the drop down menu if he/she decides to change it?
-
Nov 7, 2001, 11:03 #3
- Join Date
- Jul 2001
- Location
- Houston
- Posts
- 130
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
moospot-
Exactly.
Basically, I'd like to set my form up so that the user won't have to fill in any information, unless they want to or some of the info is wrong.
-
Nov 7, 2001, 11:21 #4
- Join Date
- May 2001
- Location
- Sydney, Australia
- Posts
- 2,243
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
State=bill("state") %>
<select class="fielder" name="bill[state]">
<option value="AK"<% if state="AK" then response.write " selected"%> > AK</option>
<option value="AL"<% if state="AL" then response.write " selected"%> > AL</option>
<option value="AR"<% if state="AK" then response.write " selected"%> > AK</option>
...
<option value="WI"<% if state="WI" then response.write " selected"%> > WI</option>
<option value="WV"<% if state="WV" then response.write " selected"%> > WV</option>
<option value="WY"<% if state="WY" then response.write " selected"%> > WY</option>
</select>
-
Nov 7, 2001, 11:24 #5
- Join Date
- Jul 2001
- Location
- Houston
- Posts
- 130
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
iTec-
Beautiful. Thanks.
-
Nov 7, 2001, 11:25 #6
- Join Date
- Jun 2001
- Location
- Toronto, Canada
- Posts
- 9,123
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
I would do it slightly more efficiently (skipping in and out of ASP mode is slower):
Something kinda like this:
Code:<% dim a(5) a(0)="AK" a(1)="AL" a(2)="AR" a(3)="WI" a(4)="WV" a(5)="WY" State=bill("state") mess="<select class=""fielder"" name=""bill[state]""> for i=0 to 5 if State=a(i) then selected="selected" else selected="" end if mess=mess & "<option value=""" & a(i) & """ " & selected & ">" & a(i) & "</option>" next mess=mess & "</select>" response.write mess %>
-
Nov 7, 2001, 12:09 #7
- Join Date
- May 2001
- Location
- Sydney, Australia
- Posts
- 2,243
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
no worries writhe.
yer Jerermy, i agree, but it was the firth thing that poped into my little head
-
Nov 7, 2001, 12:09 #8
- Join Date
- Jun 2001
- Location
- Toronto, Canada
- Posts
- 9,123
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
No worries, just figured I'd help out a touch. Your code would have worked, I've just been learning more about optimization recently, hence my rewrite
-
Nov 7, 2001, 12:20 #9
- Join Date
- Jul 2001
- Location
- Houston
- Posts
- 130
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Jeremy-
I'm gonna test this out in a bit. Thanks for your input ... it looks a lot faster. I'll let you know how it goes.
-
Nov 7, 2001, 12:21 #10
- Join Date
- Jun 2001
- Location
- Toronto, Canada
- Posts
- 9,123
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Great, have fun and good luck!
What we actually do is have a database, it's even better
-
Nov 7, 2001, 16:28 #11
- Join Date
- Jul 2001
- Location
- Houston
- Posts
- 130
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Jeremy-
It works fantastically. I've got one question, however. Is there a way to put in a new line character so my HTML code is a little easier to read? More simply, how do you put in a new line character? \n doesn't seem to work.
-
Nov 7, 2001, 16:35 #12
- Join Date
- Jul 2001
- Location
- Houston
- Posts
- 130
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
never mind
Jeremy-
Never mind ... I found it on MSDN: VbCrLf.
Thanks anyway.
-
Nov 7, 2001, 21:50 #13
- Join Date
- Mar 2000
- Location
- Muskegon, MI
- Posts
- 2,328
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Forgive my ignorance, but this seems rather complicated and a lot additional proccessing. What about...
Code:<select name="states"> <% selectedState = some value If Len(selectedState) > 0 Then Response.Write("<option value='" & selectedState & "'") End If %> <option value="AL"> <option value="AK"> ------- </select>
-
Nov 7, 2001, 22:26 #14
- Join Date
- Jul 2001
- Location
- Houston
- Posts
- 130
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
westmich-
The thing that makes Jeremy's code nice is that the selected state is in sequence with the alphabetical list of states. If I understand your code correctly, the selected state comes before the rest of the states. If, for example, the selected state is TX, it will come before AK in an alphabetical list.
-
Nov 7, 2001, 22:32 #15
- Join Date
- Jun 2001
- Location
- Toronto, Canada
- Posts
- 9,123
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
We've wrestled with this, and in terms of usability and clarity it really is best to do the "extra processing" which in reality isn't really extra processing because:
-There's no response buffer
-You're not switching modes
Couple of extra lines perhaps, but unnoticeable if there is a tiny slowdown.
Bookmarks