SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Zealot
    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 %>">
    That works great for all the text fields, but I'm not sure how to do it for a select field, which I'm using for the customer to choose which state they are from. Code is like so:
    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>
    I want the form to automatically select whichever state I tell it to, based on the hidden fields. Has anyone done this before?
    Last edited by writhe; Nov 7, 2001 at 09:54.

  2. #2
    Xbox why have you forsaken me? moospot's Avatar
    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?

  3. #3
    SitePoint Zealot
    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.

  4. #4
    SitePoint Wizard iTec's Avatar
    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>

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Houston
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    iTec-

    Beautiful. Thanks.

  6. #6
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    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
    %>
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  7. #7
    SitePoint Wizard iTec's Avatar
    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

  8. #8
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    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
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  9. #9
    SitePoint Zealot
    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.

  10. #10
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    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
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  11. #11
    SitePoint Zealot
    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.

  12. #12
    SitePoint Zealot
    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.

  13. #13
    SitePoint Wizard westmich's Avatar
    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>
    The dynamic value is simply appended to the top of the normal select list.
    Westmich
    Smart Web Solutions for Smart Clients
    http://www.mindscapecreative.com

  14. #14
    SitePoint Zealot
    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.

  15. #15
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    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.
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •