What\'s wrong with this code?
jQuery
$(document).ready(function() {
$(\"#routetype\").val(\'quietest\');
)};
HTML
&
You need to select jQuery in the dropdown on the left and you have a syntax error because the $(document).ready
should end with });
not )};
Check this link.
You can select dropdown option value by name
jQuery("#option_id").find("option:contains('Monday')").each(function()
{
if( jQuery(this).text() == 'Monday' )
{
jQuery(this).attr("selected","selected");
}
});
UPDATED ANSWER:
Old answer, correct method nowadays is to use jQuery's .prop()
. IE, element.prop("selected", true)
OLD ANSWER:
Use this instead:
$("#routetype option[value='quietest']").attr("selected", "selected");
Fiddle'd: http://jsfiddle.net/x3UyB/4/