RSS Forums RSS

ASP server side validation: Retaining form selections after posting

Reply
Posts: 1
Reputation: cmoc is an unknown quantity at this point 
Solved Threads: 0
cmoc cmoc is offline Offline
Newbie Poster

ASP server side validation: Retaining form selections after posting

  #1  
Sep 8th, 2008
i am new to asp and would much appreciate your help with my problem.
i am trying to retain the selected "state" input from my form's drop down menu after it is posted and then gets returned to the form page for incorrect or additional input on the form. Presently, the input the user selected disappears when redirected back to the form. So when the user selects a state from the drop down list, how can i have it reappear in the selected field after posting so the user does not have to input it over again.

here is a bit of my code i have tried but it does not work as of yet.

  1. <select name="State">
  2. <option value="">&lt;Select State&gt;</option>
  3. <option value="AL"<% If State = "AL" Then Response.Write(" selected=""selected""") %>>Alabama</option>
  4. <option value="AK"<% If State = "AK" Then Response.Write(" selected=""selected""") %>>Alaska</option>
  5. <option value="AZ"<% If State = "AZ" Then Response.Write(" selected=""selected""") %>>Arizona</option>
  6. <option value="AR"<% If State = "AR" Then Response.Write(" selected=""selected""") %>>Arkansas</option>
  7. <option value="CA"<% If State = "CA" Then Response.Write(" selected=""selected""") %>>California</option>
  8. <option value="CO"<% If State = "CO" Then Response.Write(" selected=""selected""") %>>Colorado</option>
  9. <option value="CT"<% If State = "CT" Then Response.Write(" selected=""selected""") %>>Connecticut</option>
  10. <option value="DC"<% If State = "DC" Then Response.Write(" selected=""selected""") %>>District of Columbia</option>
  11. <option value="DE"<% If State = "DE" Then Response.Write(" selected=""selected""") %>>Delaware</option>
  12. <option value="FL"<% If State = "FL" Then Response.Write(" selected=""selected""") %>>Florida</option>
  13. <option value="GA"<% If State = "GA" Then Response.Write(" selected=""selected""") %>>Georgia</option>
  14. <option value="HI"<% If State = "HI" Then Response.Write(" selected=""selected""") %>>Hawaii</option>
  15. <option value="ID"<% If State = "ID" Then Response.Write(" selected=""selected""") %>>Idaho</option>
  16. <option value="IL"<% If State = "IL" Then Response.Write(" selected=""selected""") %>>Illinois</option>
  17. <option value="IN"<% If State = "IN" Then Response.Write(" selected=""selected""") %>>Indiana</option>
  18. <option value="IA"<% If State = "IA" Then Response.Write(" selected=""selected""") %>>Iowa</option>
  19. <option value="KS"<% If State = "KS" Then Response.Write(" selected=""selected""") %>>Kansas</option>
  20. <option value="KY"<% If State = "KY" Then Response.Write(" selected=""selected""") %>>Kentucky</option>
  21. <option value="LA"<% If State = "LA" Then Response.Write(" selected=""selected""") %>>Louisiana</option>
  22. <option value="ME"<% If State = "ME" Then Response.Write(" selected=""selected""") %>>Maine</option>
  23. <option value="MD"<% If State = "MD" Then Response.Write(" selected=""selected""") %>>Maryland</option>
  24. <option value="MA"<% If State = "MA" Then Response.Write(" selected=""selected""") %>>Massachusetts</option>
  25. <option value="MI"<% If State = "MI" Then Response.Write(" selected=""selected""") %>>Michigan</option>
  26. <option value="MN"<% If State = "MN" Then Response.Write(" selected=""selected""") %>>Minnesota</option>
  27. <option value="MS"<% If State = "MS" Then Response.Write(" selected=""selected""") %>>Mississippi</option>
  28. <option value="MO"<% If State = "MO" Then Response.Write(" selected=""selected""") %>>Missouri</option>
  29. <option value="MT"<% If State = "MT" Then Response.Write(" selected=""selected""") %>>Montana</option>
  30. <option value="NE"<% If State = "NE" Then Response.Write(" selected=""selected""") %>>Nebraska</option>
  31. <option value="NH"<% If State = "NH" Then Response.Write(" selected=""selected""") %>>New Hampshire</option>
  32. <option value="NJ"<% If State = "NJ" Then Response.Write(" selected=""selected""") %>>New Jersey</option>
  33. <option value="NM"<% If State = "NM" Then Response.Write(" selected=""selected""") %>>New Mexico</option>
  34. <option value="NY"<% If State = "NY" Then Response.Write(" selected=""selected""") %>>New York</option>
  35. <option value="NV"<% If State = "NV" Then Response.Write(" selected=""selected""") %>>Nevada</option>
  36. <option value="NC"<% If State = "NC" Then Response.Write(" selected=""selected""") %>>North Carolina</option>
  37. <option value="ND"<% If State = "ND" Then Response.Write(" selected=""selected""") %>>North Dakota</option>
  38. <option value="OH"<% If State = "OH" Then Response.Write(" selected=""selected""") %>>Ohio</option>
  39. <option value="OK"<% If State = "OK" Then Response.Write(" selected=""selected""") %>>Oklahoma</option>
  40. <option value="OR"<% If State = "OR" Then Response.Write(" selected=""selected""") %>>Oregon</option>
  41. <option value="PA"<% If State = "PA" Then Response.Write(" selected=""selected""") %>>Pennsylvania</option>
  42. <option value="RI"<% If State = "RI" Then Response.Write(" selected=""selected""") %>>Rhode Island</option>
  43. <option value="SC"<% If State = "SC" Then Response.Write(" selected=""selected""") %>>South Carolina</option>
  44. <option value="SD"<% If State = "SD" Then Response.Write(" selected=""selected""") %>>South Dakota</option>
  45. <option value="TN"<% If State = "TN" Then Response.Write(" selected=""selected""") %>>Tennessee</option>
  46. <option value="TX"<% If State = "TX" Then Response.Write(" selected=""selected""") %>>Texas</option>
  47. <option value="UT"<% If State = "UT" Then Response.Write(" selected=""selected""") %>>Utah</option>
  48. <option value="VT"<% If State = "VT" Then Response.Write(" selected=""selected""") %>>Vermont</option>
  49. <option value="VA"<% If State = "VA" Then Response.Write(" selected=""selected""") %>>Virginia</option>
  50. <option value="WA"<% If State = "WA" Then Response.Write(" selected=""selected""") %>>Washington</option>
  51. <option value="WV"<% If State = "WV" Then Response.Write(" selected=""selected""") %>>West Virginia</option>
  52. <option value="WI"<% If State = "WI" Then Response.Write(" selected=""selected""") %>>Wisconsin</option>
  53. <option value="WY"<% If State = "WY" Then Response.Write(" selected=""selected""") %>>Wyoming</option>
  54.  
  55. </select>



looking forward to your reply
Last edited by peter_budo : Sep 10th, 2008 at 6:37 pm. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Posts: 185
Reputation: aparnesh is an unknown quantity at this point 
Solved Threads: 10
aparnesh's Avatar
aparnesh aparnesh is offline Offline
Junior Poster

Re: ASP server side validation: Retaining form selections after posting

  #2  
Sep 11th, 2008
1. Before posting, store the value (in this case the selectedIndex of the SELECT) you want in a hidden control (INPUT TYPE = "Hidden" etc...)
2. Accept the value in the page accepting the post in a Server side variable.
3.When you return to the original page, obtain the server variable in a client side variable using javascript (var Clientvar = <%=ServerVar%> ; )
4. Set the selectedIndex of the SELECT as the client variable (<<Select_Name>>.selectedIndex = Clientvar)
Last edited by aparnesh : Sep 11th, 2008 at 2:32 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 1093 | Replies: 1 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:58 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC