Forum Moderators: open

Message Too Old, No Replies

form event

         

stevelibby

1:15 pm on Sep 4, 2009 (gmt 0)

10+ Year Member



hi i have a piece of code:
Response.Write("<select name=""category"" id=""category"" onchange=""retrievesubcategory();"" style=""width:210px"";>")

which works absolutely fine, however once retrive has done its job the submit button has been hit and directs to the next page it defualts back to select category, is there a way in which i can keep the new category onpage load?

rocknbil

5:33 pm on Sep 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, there is. Not a Javascript question, but just the same,

You don't show us how you write the options, but it should go something like this.


<%
For each val in optionList
Response.Write ("<option value="" & val)
If (Request.Form("category")=val)
Response.Write(" selected")
End If
Response.Write(">" & val & "</option>"& vbCR);
Next
%>

My VBScript/ASP is a bit rusty (is vbCR still a carriage return?) and this may have errors, but you get the idea. When outputting the list, if the value is present and matches one of the options, set it to " selected" and don't forget the space before the word "selected".

<option value="some-value" selected>some-value</option>