Change the Value of jQuery Drop-Down List from Known Values
In jQuery, setting the value of a drop-down list is straightforward. However, issues may arise when using certain ID selectors.
jQuery's Value Setting
jQuery's documentation states that the $.val method "checks or selects all the radio buttons, checkboxes, and select options that match the set of values."
Correct Code:
To correctly set the drop-down list's value, use the following code:
$("._statusDDL").val('2');
Rendering the Option in Front-End
To display the selected option in the drop-down list's front-end, add ".change()" to the code:
$("._statusDDL").val('2').change();
Note for Internet Explorer 6
In Internet Explorer 6, an "Invalid Index" error may occur when setting the selected property. This appears to be a bug in IE6.
The above is the detailed content of How Do I Correctly Set the Value of a jQuery Drop-Down List?. For more information, please follow other related articles on the PHP Chinese website!