1document.getElementById('personlist').getElementsByTagName('option')[11].selected = 'selected'
2
1<form name="AddAndEdit">
2 <select name="list" id="personlist">
3 <option value="P1">Person1</option>
4 <option value="P2">Person2</option>
5 <option value="P3">Person3</option>
6 </select>
7</form>
1(function() {
2
3 // get references to select list and display text box
4 var sel = document.getElementById('scripts');
5 var el = document.getElementById('display');
6
7
8 function getSelectedOption(sel) {
9 var opt;
10 for ( var i = 0, len = sel.options.length; i < len; i++ ) {
11 opt = sel.options[i];
12 if ( opt.selected === true ) {
13 break;
14 }
15 }
16 return opt;
17 }
18
19 // assign onclick handlers to the buttons
20 document.getElementById('showVal').onclick = function () {
21 el.value = sel.value;
22 }
23
24 document.getElementById('showTxt').onclick = function () {
25 // access text property of selected option
26 el.value = sel.options[sel.selectedIndex].text;
27 }
28
29 document.getElementById('doLoop').onclick = function () {
30 var opt = getSelectedOption(sel);
31 el.value = opt.value;
32 }
33
34}());
35// immediate function to preserve global namespace
36