i have a combo box with id="combo1", i want to get the selected item or value through javascript. help me plz...
how to get selected item or value of html-combo box through javascript?
Collapse
X
-
Tags: None
-
I don't know what you want to get the value with but here is an example with a button:
Code:<html> <head> <script language="javascript"> function combofunction(the_value){ // actions that you want to perform } </script> </head> <body> <select name="htmlcombo"> <option name="box1" value="Value1">Display Text1</option> <option name="box2" value="Value2">Display Text2</option> <option name="box3" value="Value3">Display Text3</option> </select> <input type="button" name="combovalue" value="Get Combo Value" onclick="combofunction(htmlcombo.value)"> </body> </html>
-
Originally posted by nirmalsinghi have a combo box with id="combo1", i want to get the selected item or value through javascript. help me plz...
Code:var combo1 = document.getElementById("combo1"); var val = combo1.options[combo1.selectedIndex].text
Comment
-
Originally posted by nirmalsinghi have a combo box with id="combo1", i want to get the selected item or value through javascript. help me plz...
[code=html]function getCombo1(sel) {
var value = sel.options[sel.selectedInd ex].value;
}
<select id="combo1" onchange="getCo mbo1(this)">
<option value="">Select combo</option>
<option value="Value1"> Text1</option>
<option value="Value2"> Text2</option>
<option value="Value3"> Text3</option>
</select>[/code]
Ronald :cool:Comment
-
Code:<input type="button" onclick="change(selectname.options[selectname.selectedIndex].value)"
Comment
-
I did type this on January the 1st, 2007, but now I'd say that you should use document.getEle mentById(), though using the form name via document.forms[] is also valid. I'd also add that you can use the following code (as long as you have set the values of each of the options):
Code:var combo1 = document.getElementById("combo1").value;
Comment
-
I did type this on January the 1st, 2007, but now I'd say that you should use document.getEle mentById(), though using the form name via document.forms[] is also valid. I'd also add that you can use the following code (as long as you have set the values of each of the options):
Code:var combo1 = document.getElementById("combo1").value;
Comment
-
Bala D
button:
Code:<input name="btnGo" value=" Search " class="seinput" type="submit" onclick="javascript:submitSearch();">
Code:<select name="category" class="catpinput"> <option value="-1" selected="selected">All Category</option>
Code:function submitSearch() { var catkey = $('.catpinput').val(); window.alert(catkey); }
Last edited by acoder; Oct 14 '10, 08:45 AM.Comment
Comment