how to preserve a select box state

liunx

Guest
Hi everyone,<br />
I need some help with this:<br />
I have the follwing select box on a web page.<br />
<br />
<select name="countries[]"><br />
<option value="">Select a country</option><br />
<option value="Afghanistan ">Afghanistan </option><br />
<option value="Albania ">Albania</option><br />
<option value="Algeria ">Algeria </option><br />
<option value="Andorra">Andorra </option><br />
..<br />
..<br />
..<br />
<option value="Zimbabwe ">Zimbabwe </option><br />
</select><br />
<br />
When the user selects a country and clicks on a button "Search", the list goes back and shows "Select a country", what I want is how to preserve the selected coutry until the user chooses another one or refresh the page.<br />
<br />
Thanks in advance.<!--content-->The best way is to do it on the server when you build the page for the response.<!--content-->Hi,<br />
This code may help you<br />
<br />
Bhanu<br />
-------------------------------------------<br />
<HEAD><br />
<br />
<br />
<br />
<BODY><br />
<form name="form" action=""><br />
<input type="hidden" name="cty" ><br />
<br />
<select name="countries"><br />
<option value="">Select a country</option><br />
<option value="Afghanistan ">Afghanistan </option><br />
<option value="Albania ">Albania</option><br />
<option value="Algeria ">Algeria </option><br />
<option value="Andorra">Andorra </option><br />
<option value="Zimbabwe ">Zimbabwe </option><br />
</select><br>Selected county : <input type="text" name="cty1" ><br><br />
<SCRIPT LANGUAGE="JavaScript"><br />
var a = window.location;<br />
document.all['cty'].value = a;<br />
c = document.all['cty'].value<br />
aLen = c.indexOf("cty1");//alert(aLen);<br />
b = c.indexOf("countries=");<br />
d= c.substring(b+10,aLen-2);<br />
if(b>0){<br />
document.all['cty1'].value = d;}<br />
for(j=0;j<document.all['countries'].length;j++){<br />
if(document.all['countries'][j].text == d){<br />
document.all['countries'][j].selected = true;<br />
}<br />
}<br />
document.all['cty'].value = "";<br />
</script><br />
<br />
<br />
<input type="submit" value="Submit"><br />
<br />
</form><br />
--------------------------------------<!--content-->
 
Back
Top