Get select menu value using jQuery

Hi all,

I have a form with a select menu which posts back to the same page. How can I use jQuery to get the selected value? The below code retrieves the selected value but I need the value when the form has been submitted AND the new page reloaded. The value must be available once the page reloads.

Hope this makes sense!

Please help - thanks in advance.

 $(document).ready(function () {
  $(".myform").submit(function(){
  var selectedoption = $("select").val()
});   
});  

your given code is pointless as triggering a form submit will make you leave the page and thus any changes made so far will be lost. (unless you save them anywhere)

despite that, when you freshly load a page (no matter if it is the initial load or a reload after a form submit) your select will always yield your default option (which may be set through server-side scripting).

The value must be available once the page reloads.

then you need a means (e.g. cookies, WebStorage) to indicate that the current page load comes from a reload. and when you’re at that you can save the select’s value from before the submit there as well.

Ok thank you.