I have;
<form method="post" action="search.php">
<select name="country" class="dropdownselect" >
<option value="">Select Country</option>
<option value="Afghanistan" selected="selected">Afghanistan</option>
<option value="Albania" selected="selected">Albania</option>
<option value="Algeria" selected="selected">Algeria</option>
</select>
</form>
And then in search.php;
$country = $country;
+
SQL query for $country..
I need to save DropDown selection to stay selected when someones preform search.
Can it be done with HTML5 storage func?
Thanks in advance
I have;
<form method="post" action="search.php">
<select name="country" class="dropdownselect" >
<option value="">Select Country</option>
<option value="Afghanistan" selected="selected">Afghanistan</option>
<option value="Albania" selected="selected">Albania</option>
<option value="Algeria" selected="selected">Algeria</option>
</select>
</form>
And then in search.php;
$country = $country;
+
SQL query for $country..
I need to save DropDown selection to stay selected when someones preform search.
Can it be done with HTML5 storage func?
Thanks in advance
Share edited Oct 8, 2012 at 20:04 Michal Klouda 14.5k7 gold badges56 silver badges79 bronze badges asked Oct 8, 2012 at 19:38 xulxul 2105 silver badges15 bronze badges1 Answer
Reset to default 8Yes, you can store it on select change and then read on page load:
$(document).ready(function() {
var item = window.localStorage.getItem('country');
$('select[name=country]').val(item);
$('select[name=country]').change(function() {
window.localStorage.setItem('country', $(this).val());
});
});
DEMO