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


I have a drop-down list with known values, what I'm trying to do is drop down the list Special value is set in which I know that using jQuery is present. Using regular javascript, I do something like this:

  ddl = document.getElementById ("The id of element goes here"); Ddl.value = 2; // I want to set it up to 2 value  

However, I need to do this with jQuery, because I have a CSS class for my selector (stupid client ID) I am using.

Here are some things I've tried:

  $ ("._stationDDL"). Val (2); // 2 was not found as a value of $ ("._stationDDL"). Children ("Options"). Val (2) // also fail  

How can I do this with jQuery?

Update

with the first time:

  $ ("._stationDDL"). Val (2);  

When I put a warning on it, it works fine, but when I remove the warning and run it at full speed, I get an error.

The selected asset could not be set invalid indices

I'm not sure whether it is with jQuery or Internet Explorer 6 (I'm guessing Internet Explorer 6) There is a bug, but it is very annoying.

:

[jQuery.val] check, or Select Selects , the option to match all the radio buttons, checkboxes, and values ​​set.

This behavior is in jQuery versions 1.2 and above.

You need it most:

  $ ("._stationDDL"). Val ('2');  

Comments