Possible Duplicate:
Html select option lost data after submit
I have a select menu that should keep the selected option after the page refresh. This is the example:
<select id="form_frame" name="frame" onchange="getData(this);"/>
<option value="data1" selected="selected">Data 1</option>
<option value="data2">Data 2</option>
</select>
Function getData just pull info to the user.
I'm using Smarty/php for the dynamic content.
Open to advice, thanks!
How it's done with local storage :
$(function() {
if (localStorage.getItem('form_frame')) {
$("#form_frame option").eq(localStorage.getItem('form_frame')).prop('selected', true);
}
$("#form_frame").on('change', function() {
localStorage.setItem('form_frame', $('option:selected', this).index());
});
});
FIDDLE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With