1// highlight text in an input element
2element.select();
3
4// highlight a portion of an element
5// element.setSelectionRange(start, end, ?direction)
6// start, end - start and end indices of the new selection
7// direction (optional) - "forward", "backward", or "none" (default)
8element.setSelectionRange(3, 5);
1<select id="box1" onChange="myNewFunction(this);">
2 <option value="98">dog</option>
3 <option value="7122">cat</option>
4 <option value="142">bird</option>
5</select>
6<script>
7 function myNewFunction(sel) {
8 alert(sel.options[sel.selectedIndex].text);
9}
10</script>