Here is a little code snippet that works somewhat well but not quite what I am trying to achieve:
<html>
<head>
</head>
<body>
<form method='post'>
Display
<select name="displayOptions" onchange="this.form.submit()">
<option selected value="all">all</option>
<option value="open">open</option>
<option value="reserved">reserved</option>
<option value="blocked">blocked</option>
</select> computers
</form>
<?php
if(isset($_POST["displayOptions"])){
if ($_POST["displayOptions"]=='all')
allFunction();
if ($_POST["displayOptions"]=='open')
openFunction();
etc...
}
?>
</body>
</html>
As soon as the user chooses a dropdown selection I want the action to take place. I also want the default action to be "all" and for that to happen as soon as the form is loaded. The code snippet above works well with the exception of 2 things.
- 'all' is selected by default (Working As Intended), however allFunction() doesn't run. Even if you select another option and then select 'all' again, 'all' still doesn't work. I would like the allFunction to run as soon as this form loads up with 'all' selected and, of course, to be able to choose 'all' again later.
- Whenever a different selection is selected, it loads the correct function (WAI), however the dropdown turns back to all. I know why it does this (becuase the page is being reloaded and 'all' is the default selected value), but I'd like it to stay on the selected option!
As I typed this out I have a feeling I can tackle #2 with a $_SESSION variable but I am still stumped why the first option in the select dropdown is not registering.