Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <select name="mySelect" id="mySelect">
- <option value="1" id="option1">1</option>
- <option value="2" id="option2">2</option>
- </select>
- 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);
- }
- // replace 1 with index of an item you want to select
- options[1].selected = true;
- $$('#mySelect option').find(function(ele){return !!ele.selected})
- var selectThis = 'option1';
- $$('select#mySelectId option').each(function(o) {
- if(o.readAttribute('value') == selectThis) { // note, this compares strings
- o.selected = true;
- throw $break; // remove this if it's a multi-select
- }
- });
- $('mySelect').setValue(1); // or whatever value you want to select
- var myChoice = '2';
- $$('select#mySelectId option').each(function(o) {
- o.selected = o.readAttribute('value') == myChoice;
- });
- var itis = $(mySelectId).select('option[value="' + sValueToSelect + '"]');
- if ( itis && itis.length > 0 )
- itis[0].selected = true;
- var selectThis = 'option1';
- $$('select#mySelect option').each(function(o){
- if(o.id==selectThis){o.selected = true;$break;}
- });
- $('mySelect').value = 2; // 2 being the value you want selected
- document.observe('dom:loaded', function() {
- $('mySelect').observe('change', function(event) {
- ...
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment