Javascript saves the selected value from the list after submitting the form

I have a small form with a list selected, and I submit the form every time I select an item. the problem is that after selecting a value and submitting the form, the selected item does not remain selected. Is there a way to save the selected item selected in the list after submitting the form? (e.g. using javascript)?

<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!

+3
source share
2 answers

If you cannot use the solution on the server side, you can set a cookie after running onchange-Event and submit the form. For information on javascript cookies, check out the following site: http://www.quirksmode.org/js/cookies.html

+1

, AJAX? jQuery, , .

jQuery('#order_of_products_by_values').change(function() { 

    jQuery.post('ajax/test.php', jQuery("#order_of_products_by_values_FORM").serialize());

});

, , , , .

test.php script, . :

$select = $_POST['order_of_products_by_values'];
0

Source: https://habr.com/ru/post/1796683/


All Articles