Reputation: 24851
<select class="goog-te-combo">
<option value="">select</option>
<option value="ja">japan</option>
</select>
After page has loaded, I want to select the option whose value is "ja", i want to use prototype to do this automatic, anyone can help me ? thanks!
Upvotes: 0
Views: 2543
Reputation: 37700
The answer seems obvious:
$$('option[value=ja]').first().selected = true;
Upvotes: 4
Reputation: 34642
Assuming you assigned an id
to the <select>
:
(function(element) {
$A(element.options).each(function(option, index) {
if ('ja' == option.value)
element.selectedIndex = index;
});
})( $('select-id') );
To retrieve all <select>
elements of a given class, do:
$$('select.class_name_here').each(function(element) {
$A(element.options).each(function(option, index) {
if ('ja' == option.value)
element.selectedIndex = index;
});
});
Please refrain from using "denglish" in your code; it makes it look unsexy.
Upvotes: 1