Jquery select option change selected

Jquery select option change selected

Posted: DenisRUS Date: 09.07.2017

I have a drop-down list with known values. What I'm trying to do is set the drop down list to a particular value that I know exists using jQuery. Using regular JavaScript, I would do something like:.

However, I need to do this with jQuery, because I'm using a CSS class for my selector stupid ASP. When I put an alert just above it it works fine, but when I remove the alert and let it run at full speed, I get the error.

jquery - Set select option 'selected', by value - Stack Overflow

I'm not sure if it's a bug with jQuery or Internet Explorer 6 I'm guessing Internet Explorer 6 , but it's terribly annoying.

I have one drop-down list with some values and I want to select the same value from another drop-down list So first I put in a variable the selectIndex of my first drop-down. Because in my case, I'm using selected option's data attribute instead of value attribute. So if you do not have unique value for each option, above method is the shortest and sweet!!

These solutions seem to assume that each item in your drop down lists has a val value relating to their position in the drop down list. So Item 4 will show as "Selected" in the browser and now you want to change the value as 3 and show "Item3" as selected instead of Item4. So as per the above solutions,if you use. You will see that Item 3 as selected in browser. But when you process the data either in php or asp , you will find the selected value as "4".

The reason is that , your html will look like this. I would appreciate comments on this from senior programmers like strager , y0mbo , ISIK and others. So I changed it so that now it executes after a miliseconds using setTimeout.

Seems to be working now.

How to change options of