1<select id="ddlViewBy">
2 <option value="1">test1</option>
3 <option value="2" selected="selected">test2</option>
4 <option value="3">test3</option>
5</select>
6Running this code:
7
8var e = document.getElementById("ddlViewBy");
9var strUser = e.value;
10Would make strUser be 2. If what you actually want is test2, then do this:
11
12var e = document.getElementById("ddlViewBy");
13var strUser = e.options[e.selectedIndex].text;
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>