Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 795
dana Avatar asked Dec 14 '25 14:12

dana


1 Answers

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

like image 103
fabian-mcfly Avatar answered Dec 16 '25 14:12

fabian-mcfly