javascript - Change the selected value of a drop-down list with jQuery -


i have drop-down list known values. i'm trying set drop down list particular value know exists using jquery. using regular javascript, like:

ddl = document.getelementbyid("id of element goes here"); ddl.value = 2; // 2 being value want set to. 

however, need jquery, because i'm using css class selector (stupid asp.net client ids...).

here few things i've tried:

$("._statusddl").val(2); // doesn't find 2 value. $("._statusddl").children("option").val(2) // failed. 

how can jquery?

update

so turns out, had right first time with:

$("._statusddl").val(2); 

when put alert above it works fine, when remove alert , let run @ full speed, error

could not set selected property. invalid index

i'm not sure if it's bug jquery or internet explorer 6 (i'm guessing internet explorer 6), it's terribly annoying.

jquery's documentation states:

[jquery.val] checks, or selects, radio buttons, checkboxes, , select options match set of values.

this behavior in jquery versions 1.2 , above.

you want this:

$("._statusddl").val('2'); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -