I have form with some text inputs and dropdown menus. This elements are generated dynamically based on the user selection in the previous page and this dynamic generation of elements are working fine. Now, let's say my code looks like this -
<form id="myForm" >
<select id='id1'>
<option value="">Select an option</option>
<option value="opt1">opt1</option>
<option value="opt2">opt2</option>
<option value="opt3">opt3</option>
</select>
<select id='id2'>
<option value="">Select an option</option>
<option value="Apple">Apple</option>
<option value="Orange">Orange</option>
<option value="Grape">Grape</option>
</select>
</form>
and now i wanted to reset the option of all the dropdown menu item to the first i.e. - "Select an option" when user clicks on reset button.
<button class="reset-field" id="clearBtn">Reset</button>
For this i tried-
$(document).ready(function(){
...
$("#clearBtn").click(function(){
$('#myForm select').each(function(key, value) {
$(this).val("");
});
});
});
Basically this sets the value to "" but not the the option. I mean selected item is not getting changed. Any idea how we can set the option to - "Select an option".
Thanks.