retain selected value in a dropdown list

Reply

Join Date: Aug 2005
Posts: 52
Reputation: spidey is an unknown quantity at this point 
Solved Threads: 0
spidey's Avatar
spidey spidey is offline Offline
Junior Poster in Training

retain selected value in a dropdown list

 
0
  #1
Jan 20th, 2008
Hello,

I have a dropdown list (single row only) of languages. If I select 'English", the page will reload, it will pass a variable of the Language ID, and all records in English will display in the table.
How can I retain the value selected in the dropdown? I want the selected language to be selected (displayed) in the dropdown list, not the first nor last.
Thanks in advance!
  1. <select name="LanguageID" onchange="myForm.submit();">
  2. <%do while not rs.eof%>
  3. <option value="<%=rs("LanguageID")%>"><%=rs("Language")%></option>
  4. <%rs.movenext
  5. loop%>
  6. </select>
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: retain selected value in a dropdown list

 
0
  #2
Jan 21st, 2008
well you can always do it via querystring or session's. just set the querystring or session to the language ID. then do this:
  1. <select name="LanguageID" onchange="myForm.submit();">
  2. <%do while not rs.eof%>
  3. <option value="<%=rs("LanguageID")%>" <% if Trim(Request.QueryString("languageid")) = rs("LanguageID") then %>selected<% end if %>><%=rs("Language")%></option>
  4. <%rs.movenext
  5. loop%>
  6. </select>
or session object:
  1. <select name="LanguageID" onchange="myForm.submit();">
  2. <%do while not rs.eof%>
  3. <option value="<%=rs("LanguageID")%>" <% if Session("languageid") = rs("LanguageID") then %>selected<% end if %>><%=rs("Language")%></option>
  4. <%rs.movenext
  5. loop%>
  6. </select>
Last edited by SheSaidImaPregy; Jan 21st, 2008 at 10:17 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the ASP Forum
Thread Tools Search this Thread



Tag cloud for ASP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC