Hi All,
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.
[HTML]
<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_n ame.select_elem ent_name.select edIndex;"
Pl. do reply me.
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.
Code:
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_n ame.select_elem ent_name.select edIndex;"
Pl. do reply me.
Comment