Keep the selected value after submit

html, jquery

Solution

If you have the jQuery Cookie Plugin, you can use it to store the value of the select into cookie every time a selection is made and whenever the form loads it would check if the cookie is set and use the value in the cookie.

$(function() {
    var timeCookie = $.cookie( "timeCookie" ),
        selElem = $('select[name=pickupdatehour]');
    selElem.on('change', function() {
        $.cookie( "timeCookie", this.value );
    });
    if( timeCookie != undefined ) {
        selElem.val( timeCookie );
    } else {
        $.cookie( "timeCookie", selElem.val() );
    }
});

HERE IS a working demo.

Problem

I have a time drop down selection and i want to keep the selected value after the submit button has been pressed. Html here ``` <select name="pickupdatehour"> <option label="00" selected="selected" value="00">00</option> <option label="01" value="1">01</option> <option label="02" value="2">02</option> ... <option label="23" value="23">23</option> </select> ``` I'm not using regular php for this because i'm making a site in wordpress and i would need a ton of snippets to do this,i have this select box on multiple pages and i would need a Java or jQuery script to help me keep the selected value on each page.

Original source