I am passing ID of the HTML SELECT element to a javascript function.
In that function I need to access the value selected in that select box.
I tried the following code. but it didn't work.
Expand|Select|Wrap|Line Numbers
- function save()
- {
- var x='bid';
- res=document.bform.x.options[document.x.selectedIndex].value;
- alert(res);
- }
<form name="bform" >
<select id="bid" name="bid">
<option value="1">1
<option value="2">2
</select>
<input type="button" onClick="save();">
</form>
[/HTML]
My problem is , I am having id value of the select box in a variable.
How can I use that value while calling "document.frm_name.select_element_name.selectedInd ex;"
Pl. do reply me.