jQuery / Programmatically Select an Option in Select Box

update:

As of jQuery 1.9, jQuery has updated this functionality. The “selected” state of an option is actually a property, therefore jQuery has changed this to use the .prop() method. Syntax is very similar and easy to switch:

$('#startTime option[value=17:00:00]').prop('selected', true);

See http://api.jquery.com/prop/#entry-longdesc for why it needs to pass true.


Older jQuery

$('#startTime option[value=17:00:00]').attr('selected', 'selected');

or

$('#startTime option[value="+ data[0].start +"]').attr('selected', 'selected');

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)