How do I select an option using prototype

var options = $$('select#mySelect option');
var len = options.length;
for (var i = 0; i < len; i++) {
    console.log('Option text=" + options[i].text);
    console.log("Option value=" + options[i].value);
}

options is an array of all option elements in #mySelect dropdown. If you want to mark one or more of them as selected just use selected property

// replace 1 with index of an item you want to select
options[1].selected = true;

Leave a Comment

File not found.