Search code examples
javascriptformsselected

javascript keep a selected value from a list after form submit


i have a little form with a select list, and i am submitting the form every time i select an item. the problem is that, after selecting a value and submitting the form, the selected item doesn't remain selected. Is there any method to keep the selected item selected in the list, after the form submit? (using javascript for example)?

<form name="order_of_products_by_values" id="order_of_products_by_values" method="post" action="">
<select id="order_of_products_by_values" name="order_of_products_by_values"  onChange="this.form.submit();">   
<option value=1 >Pret crescator</option>
<option value=2 >Pret descrescator</option>
<option value=3 >Test</option>
<option value=4 >Test</option>
</select>
</form>

thank you!


Solution

  • If you can't use a server side solution, you could set a cookie after the onchange-Event fires and submit the form. For informations about javascript cookies, take a look at the following site: http://www.quirksmode.org/js/cookies.html