114
rated 0 times
[
115]
[
1]
/ answers: 1 / hits: 91115
/ 12 Years ago, mon, september 24, 2012, 12:00:00
Below is code for select option and generate using php from database and i try to add selected=selected
to value=4
using jQuery or any javascript:
<select id=countryselect name=country>
<option value=1>Afghanistan</option>
<option value=2>Albania</option>
<option value=3>Algeria</option>
<option value=4>Malaysia</option>
<option value=5>Maldives</option>
</select>
i try to refer this post but still can't .. below is my current script :
<script>
localStorage.setItem(Select1, Malaysia);
$('#countryselect').find('option').each(function(i,e){
if($(e).val() == localStorage.getItem(Select1)){
$('#countryselect').prop('selectedIndex',i);
}
});
</script>
thanks.
More From » jquery