FreelanceCoder
07-10-2012, 12:20 AM
I have two drop down menus and wish to allow the user to select from either or both and have them remember when the page reloads.
here is my code.
*************
EDIT: I have just added in the new part (just below the body tag) that I tried but still it is not remembering the previous option.
*************
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
$newURL = "";
if ($_GET['F'] != "" || $_GET['S'] != "") { $newURL .= "?"; }
if ($_GET['F'] != "") { $newURL .= "F=" . $_GET['F']; }
if ($_GET['S'] != "") { $newURL .= "S=" . $_GET['S']; }
?>
<form action="<?=$_SERVER['PHP_SELF'] . $newURL;?>" method="GET">
<select name="F" onchange="this.form.submit();">
<option>Choose an option</option>
<option value="F1"<? if($_GET['F'] == "F1") echo " SELECTED"; ?>>F1</option>
<option value="F2"<? if($_GET['F'] == "F2") echo " SELECTED"; ?>>F2</option>
</select>
</form>
<br><br>
<form action="<?=$_SERVER['PHP_SELF'] . $newURL;?>" method="GET">
<select name="S" onchange="this.form.submit();">
<option value="S1"<? if($_GET['S'] == "S1" || $_GET['S'] != "S2") echo " SELECTED"; ?>>S1</option>
<option value="S2"<? if($_GET['S'] == "S2") echo " SELECTED"; ?>>S2</option>
</select>
</form>
</body>
</html>
so lets say they select (F)irst drop down menu and choose an option, the page would reload and the option they choose will be put back in that selection. Now if they were to now select the (S)econd drop down menu and choose an option along with the previously selected option in the First menu they have already done the page would reload and now both drop down menus would have their respective values that were chosen.
This should also be the case should they select from the (S)econd drop down to start with and then select from the (F)irst drop down afterwards the same thing should happen.
No matter which order they choose the options in.
It also need to keep the option they choose in the URL using GET as the method.
Currently my code does not allow this, it reloads the page but returns the options to their defaults apart the the most recently changed option.
Can anyone suggest what method I can use to store this so either or both are stored in the URL so my script can process the options. I have not added the rest of the code yet that would process as I have yet to got the options to stay selected. So will add this in later on.
*****
Oh and yes these MUST be two separate forms.
and no I do not wish to use jquery!
*****
here is my code.
*************
EDIT: I have just added in the new part (just below the body tag) that I tried but still it is not remembering the previous option.
*************
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
$newURL = "";
if ($_GET['F'] != "" || $_GET['S'] != "") { $newURL .= "?"; }
if ($_GET['F'] != "") { $newURL .= "F=" . $_GET['F']; }
if ($_GET['S'] != "") { $newURL .= "S=" . $_GET['S']; }
?>
<form action="<?=$_SERVER['PHP_SELF'] . $newURL;?>" method="GET">
<select name="F" onchange="this.form.submit();">
<option>Choose an option</option>
<option value="F1"<? if($_GET['F'] == "F1") echo " SELECTED"; ?>>F1</option>
<option value="F2"<? if($_GET['F'] == "F2") echo " SELECTED"; ?>>F2</option>
</select>
</form>
<br><br>
<form action="<?=$_SERVER['PHP_SELF'] . $newURL;?>" method="GET">
<select name="S" onchange="this.form.submit();">
<option value="S1"<? if($_GET['S'] == "S1" || $_GET['S'] != "S2") echo " SELECTED"; ?>>S1</option>
<option value="S2"<? if($_GET['S'] == "S2") echo " SELECTED"; ?>>S2</option>
</select>
</form>
</body>
</html>
so lets say they select (F)irst drop down menu and choose an option, the page would reload and the option they choose will be put back in that selection. Now if they were to now select the (S)econd drop down menu and choose an option along with the previously selected option in the First menu they have already done the page would reload and now both drop down menus would have their respective values that were chosen.
This should also be the case should they select from the (S)econd drop down to start with and then select from the (F)irst drop down afterwards the same thing should happen.
No matter which order they choose the options in.
It also need to keep the option they choose in the URL using GET as the method.
Currently my code does not allow this, it reloads the page but returns the options to their defaults apart the the most recently changed option.
Can anyone suggest what method I can use to store this so either or both are stored in the URL so my script can process the options. I have not added the rest of the code yet that would process as I have yet to got the options to stay selected. So will add this in later on.
*****
Oh and yes these MUST be two separate forms.
and no I do not wish to use jquery!
*****