Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
181
rated 0 times [  184] [ 3]  / answers: 1 / hits: 18644  / 12 Years ago, thu, november 1, 2012, 12:00:00

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!


More From » php

 Answers
21

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


[#82242] Wednesday, October 31, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nellykaliae

Total Points: 119
Total Questions: 95
Total Answers: 103

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;