I have a select field as follows:
<select id="shippingSelect" tabindex="3" onchange="Cart.update();">
<option value="">Select Shipping Option</option>
<option value="Free">Free Shipping</option>
<option value="Reg-Airmail">Registered Airmail</option>
<option value="EMS-Express">EMS-Express Shipping</option>
<option value="DHL-Express">DHL-Express Shipping</option>
</select>
I am setting the selected value in html 5 local storage with key "shippingSelect" .
I want to disable the shipping select and display the user last selected option as selected field.
I am able to disable the select field if local storage set.
if (shipEmpty && isEmpty) {
$("#shippingSelect").attr('disabled', 'disabled');
$("#shippingSelect").css('pointer-events', 'none');
$("#shippingSelect").prop("disabled", true);
}
But the select display displays "Select Shipping Options" rather than the last user selected option value in drop down.
I tried using
if (shipEmpty && isEmpty){
$("#shippingSelect option:selected").text() );
How can i display last selected option as Selected Option. The disabled select field must display last selected option.
How is that possible in jQuery ??
update: $("#shippingSelect").val(myObject); was the solution