I'm having trouble auto-selecting the first option in a dropdown list.
I've tried using attr and val function (see this jdfiddle link for an example) and it just wouldn't work. As a a test, my example has an alert code that displays the .text() for the first option and this works fine. So my selector is working.
Thanks a lot!
sample HTML code:
<select id="rt" name="rt" style="width: 300px;">
<option value="blank" selected="selected">- Select a fruit -</option>
<option value="20270">Apple</option>
<option value="20271">Banana</option>
<option value="20273">Grapes</option>
</select>
<br>
<select id="rs" name="rs" style="width: 300px;">
<option value="blank" selected="selected">- Select a car -</option>
<option value="20226">Toyota</option>
<option value="20227">Chevy</option>
<option value="20228">Mazda</option>
</select>
sample JS code:
$("#rs").on("change", function() {
alert("rt: "+$("#rt option:first-child").text());
$("#rt option:first-child").attr("selected", "selected");
//$("#rt option:first-child").val("blank");
});