473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Save the choice made from a Drop/dwon menu?

JS
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"??
Jul 23 '05 #1
3 1735
"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>
Jul 23 '05 #2
Ivo
"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".
Is it possible to save the options that I choose from the drop/down menus
when I get back to them by pressing "Back"??


What is the code behind that Back button (and why do you need one when all
known browsers provide the very thing with plenty of prominence)? If it is
to be the same on each of those selectable pages, the code probably looks
quite generic, like

onclick="history.go(-1)"

and you need to resort to setting cookies on the originating page:

<select onchange=" dostuff(); alsosetacookie(); ">

For example http://4umi.com/web/css/changesheet.htm
contains some hilited cookie writing and reading code.

But if you can code specific url's on specific pages (a serverside script
perhaps?), something like

onclick="location.href='lastpage.html?a=5&amp;b=7' ;"

then you can read which option to select in which list from the url.
A quick n dirry approach, with a and b being references to the
respective <select> boxes:

var s = window.location.search;
if( (i = s.match( /a=(\d+)/ ) ) ) {
a.options[ i[1] ].selected=true;
}
if( (i = s.match( /b=(\d+)/ ) ) ) {
b.options[ i[1] ].selected=true;
}

should get you on the way...

hth
Ivo
Jul 23 '05 #3
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:CP********************@comcast.com...
"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"??


Can you use ASP -- it would be a lot easier to do it server-side!
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Haines Brown | last post by:
I've implemented the horizontal drop down menu discussed recently in this newsgroup, and it works nicely under Galeon and Mozilla, but not IE 5.0. Here are the problems: Under IE 5.0, the...
4
by: rajat | last post by:
Hi, I have adapted a drop down menu from USC webpage (www.usc.edu). The link to my page is http://www-scf.usc.edu/~swarup/test/test.html The links to the CSS ans JS files are:...
2
by: hemanth.singamsetty | last post by:
Hello there, I've a drop down menu (created using CSS & Javascript -- see code below). My problem is, whenever I click a link on the menu the new page replaces the current page (and the menu...
1
by: waddley | last post by:
I have a client who wants to have Access ask to save changes anytime data is changed or added into the database. I'm not really an Access guy, I actually run their servers, but have been dropped...
2
by: Paul Brady | last post by:
I have non-computer skilled users entering data into a form. There are certain ranges of values which, if they enter them, make no sense in the application, but I can't test them until they try to...
40
by: Mark G. Meyers | last post by:
http://www.savetheinternet.com There is more info and A PETITION at moveon... Easy to sign and give your two cents (and to your own reps in the process)....
3
by: rsteph | last post by:
I have a javascript drop down menu that I borrowed from a website. It utilizes a little .css to help with formatting. The menu works great, and on all 3 of the browsers I'm concerned about; but I am...
4
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
1
by: Kaland | last post by:
Do the search engines follow links that are within forms (like the drop-down menu) so that those pages are indexed? Here is the code for a sample drop-down menu that I created. <form><select...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.