"JS" <dsa.@asdf.com> wrote in message news:d8**********@news.net.uni-c.dk...
I have two drop/down menus that are dependant on each other. When I have
made a choice in both of these menus and press a button I get to a page
depending on the choice made. On this page there is two buttons "Accept"
and "Back".
When I press "Back" I would like to get back to the page with the two
menus and they should be set to the choice I made. Now the just reset when I
press the "Back" button.
Is it possible to save the options that I choose from the drop/down menus
when I get back to them by pressing "Back"??
Here's one solution. Watch for word-wrap.
<< page1.htm >>
<html>
<head>
<title><title>page1.htm</title>
<script type="text/javascript">
function submits(form) {
var form = document.form1;
var ind1 = form.sel1.selectedIndex;
var ind2 = form.sel2.selectedIndex;
if (ind1 == 0 || ind2 == 0) return false;
var sel1 = form.sel1.options[ind1].value;
var sel2 = form.sel2.options[ind2].value;
document.action += "?" + sel1 + "&" + sel2;
return true;
}
function selects() {
var qstr = location.search;
if (qstr.length < 4) {
alert("Invalid QueryString!");
return;
}
var form = document.form1;
qstr = qstr.substr(1);
var pair = qstr.split("&");
for (var i=0; i<pair.length; i++) {
var item = pair[i].split("=");
if (i == 0) {
for (var j=1; j<form.sel1.length; j++)
if (form.sel1.options[j].value == item[1]) {
form.sel1[j].selected = true;
}
}
if (i == 1) {
for (var j=1; j<form.sel2.length; j++)
if (form.sel2.options[j].value == item[1]) {
form.sel2[j].selected = true;
}
}
}
}
</script>
</head>
<body onload="selects()">
<form action="page2.htm" method="get" name="form1" onsubmit="return
submits()">
<br>
<select name="sel1">
<option value="" selected>
<option value="1">One
<option value="2">Two
<option value="3">Three
</select>
<br>
<select name="sel2">
<option value="" selected>
<option value="a">A
<option value="b">B
<option value="c">C
</select>
<br>
<input type="Submit" value="Submit">
</form>
</body>
</html>
<< page2.htm >>
<html>
<head>
<title>page2.htm</title>
<script type="text/javascript">
function backs() {
location.href = "page1.htm" + location.search;
}
function texts() {
var qstr = location.search;
if (qstr.length < 4) return;
var form = document.form1;
qstr = qstr.substr(1);
var pair = qstr.split("&");
for (var i=0; i<pair.length; i++) {
var item = pair[i].split("=");
if (i == 0) form.sel1.value = item[1];
if (i == 1) form.sel2.value = item[1];
}
}
</script>
</head>
<body onload="texts()">
<form action="page3.htm" method="get" name="form1">
<br>
<input type="text" name="sel1" readonly>
<br>
<input type="text" name="sel2" readonly>
<br>
<input type="submit" value="Accept">
<input type="button" value="Back" onclick="backs()">
</form>
</body>
</html>
<< page3.htm >>
<html>
<head>
<title>page3.htm</title>
</head>
<body>
<b>Accepted</b>
</body>
</html>