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!

I need this menu swapper to keep form's state when you go back

Status
Not open for further replies.

jondubya

Technical User
Apr 16, 2005
13
GB
I've found this lovely menu swapper from JavaScript Source which does almost exactly what I want. Only problem is that it doesn't keep track of which select variables were selected if you need to go back to that page once you've pressed submit. I've included checkboxes in the code below which do keep track of what was chosen if you need to click the browser's back button once you've left that page. Can anyone shed any light as to how I can do this? Thanks JW

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Phil Webb (phil@philwebb.com) -->
<!-- Web Site: -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! -->

<!-- Begin
function move(fbox, tbox) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for (i = 0; i < tbox.options.length; i++) {
arrLookup[tbox.options.text] = tbox.options.value;
arrTbox = tbox.options.text;
}
var fLength = 0;
var tLength = arrTbox.length;
for(i = 0; i < fbox.options.length; i++) {
arrLookup[fbox.options.text] = fbox.options.value;
if (fbox.options.selected && fbox.options.value != "") {
arrTbox[tLength] = fbox.options.text;
tLength++;
}
else {
arrFbox[fLength] = fbox.options.text;
fLength++;
}
}
arrFbox.sort();
arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c = 0; c < arrFbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrFbox[c]];
no.text = arrFbox[c];
fbox[c] = no;
}
for(c = 0; c < arrTbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrTbox[c]];
no.text = arrTbox[c];
tbox[c] = no;
}
}
// End -->
</script>

</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<form name="combo_box" action="foo.htm">
<table><tr><td>
<select multiple size="4" name="list1" style="width:150">
<option value="12">Alabama</option>
<option value="54">Alaska</option>
<option value="65">Arizona</option>
<option value="45">Arkansas</option>
<option value="2">California</option>
<option value="6">Colorado</option>
<option value="81">Connecticut</option>

</select>
</td>
<td align="center" valign="middle">
<input type="button" onClick="move(this.form.list2,this.form.list1)" value="<<">
<input type="button" onClick="move(this.form.list1,this.form.list2)" value=">>">
</td>
<td>
<select multiple size="4" name="list2" style="width:150">

</select>
</td></tr></table>
<input type="checkbox" name="checkbox" value="checkbox">
<input type="checkbox" name="checkbox2" value="checkbox">
<input type="checkbox" name="checkbox3" value="checkbox">
<input type="checkbox" name="checkbox4" value="checkbox">
<input type="checkbox" name="checkbox5" value="checkbox">
<input type="checkbox" name="checkbox6" value="checkbox">
<input type="checkbox" name="checkbox7" value="checkbox">
<input type="submit" name="google" value="Submit">
</form>

<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href=" JavaScript Source</a></font>
</center><p>

<!-- Script Size: 4.75 KB -->
 
Can you use the server side scripting that is processing this information to make a "back" link that would reselect the items previously selected?

Justin

Dyslexics of the world: Untie!
 
I plan to default the values chosen already via server-side, but this won't help if the user makes changes to these values, moves onto the next page but then clicks 'back' on the browser. If I/anyone can solve the problem of just the code above, and can make the page keep track of the <select> items after the user 'submits' and then clicks back to that page, I'll then start considering server-side scripts. Thanks for the response.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top