preserving a listbox selection
Posted: Fri May 30, 2008 7:24 am
Hi everybody, my first post here.
I have a form in which the user selects a year from a listbox and this is used as part of a database query, the results from which are displayed on the same page. Now this works perfectly well, except that when the page reloads the lisbox selection reverts to the default.
How can I preserve the selection so that it remains selected?
The form code looks like this:
<form name="form" method="post" action="<?php echo $PHP_SELF;?>">
<select name="year">
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
</select>
<input type="submit" name="Submit" value="Submit">
</form>
I think I need some sort of switch routine that defines as selected the option chosen by the user, but I am not at all sure how to implement this.
Can anyone help me?
Thanks for looking.
I have a form in which the user selects a year from a listbox and this is used as part of a database query, the results from which are displayed on the same page. Now this works perfectly well, except that when the page reloads the lisbox selection reverts to the default.
How can I preserve the selection so that it remains selected?
The form code looks like this:
<form name="form" method="post" action="<?php echo $PHP_SELF;?>">
<select name="year">
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
</select>
<input type="submit" name="Submit" value="Submit">
</form>
I think I need some sort of switch routine that defines as selected the option chosen by the user, but I am not at all sure how to implement this.
Can anyone help me?
Thanks for looking.