Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retaining select box selections after submitting page

Status
Not open for further replies.

rich0335

Programmer
Oct 16, 2001
5
US
I created two select boxes with the ability to move selections from box1 to box2. After submitting the page I would like the page to retain the selections in box2 in the event the user decides to go back and make changes. Is this possible? If so, how would this be scripted??

Thank you.
 
Using a cookie would probably the way to go. The user would of course have to have cookies turned on for this option to work, which could affect your app depending on how important this is to your users.
 
Here's a script I made that keeps the selected option selected (the example send the page to itself but you could easily change to another page etc) :

<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
<!--
function qString(str) {
theleft = str.indexOf(&quot;=&quot;) + 1;
theright = str.lastIndexOf(&quot;&&quot;);
return(str.substring(theleft,theright));
}
function setSelected(form,field,field2) {
for(var i=0; i<document[form][field].options.length; i++) {
if (qString(document[form][field2].value) == document[form][field].options.value) {
document[form][field].options.selected = true;
}
}
}
function myLoad() {
document.frm1.url.value = location
setSelected('frm1','myvar','url');
}
//-->
</script>
<body onload=&quot;myLoad()&quot;>
<form name=&quot;frm1&quot;>
<input type=&quot;hidden&quot; name=&quot;url&quot;>
<select name=&quot;myvar&quot; onchange=&quot;location='slct_chng.htm?myvar='+this.value+'&'&quot;>
<option value=&quot;var1&quot;>var1</option>
<option value=&quot;var2&quot;>var2</option>
<option value=&quot;var3&quot;>var3</option>
<option value=&quot;var4&quot;>var4</option>
<option value=&quot;var5&quot;>var5</option>
<option value=&quot;var6&quot;>var6</option>
</select>
</form> Regards

Big Bad Dave

davidbyng@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top