Jump to content

[SOLVED] Using JS to change selected value of a dropdown


kjtocool

Recommended Posts

What is the purpose of eval? A better option, IMHO, would be this:

 

var dropdown = movie_rankings['movie_' + old_rank + '_rank'];

 

Then you can simply set the selected value like this:

 

dropdown.value = 'newvalue';

 

As long as newvalue exists in the values of the options options it should be selected. Note that the value of an option is not necessarily the same as the text of the option (which is what the user sees). To set the option of a select list based upon the text you must iterrate through every option until you find a match.

eval does exactly what your method did, I used it only because I knew it worked and was unaware of the other option.  Your way is surely more efficient, thanks for the tip!

 

As for the real issue, it worked like a charm, thank you a ton!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.