Click here to Skip to main content
15,894,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
XML
<select id="Select2" ;">
                            <option>1</option>
                            <option>2</option>
                            <option>3</option>
</selecte>


i Want To Get When onChange() occured Value selected with alert response me!!!
thanks
Posted

JavaScript
<script type="text/javascript" language="javascript">
function getalert()
{
var str=document.getElementById("Select2").value;
  alert(str);
}
</script>

HTML
<select id="Select2"  önchange="getalert()">
                            <option>1</option>
                            <option>2</option>
                            <option>3</option>
</select>
 
Share this answer
 
v2
You can get either current value or selected index:
JavaScript
sel = document.getElementById("Select2");
value = sel.value;
index = sel.selectedIndex;
//use whatever you want


As to the select onchange, it is invoked when you press Enter or click on selected item, not when you change the selection, which a is pretty reasonable thing.

Please see:
http://www.w3schools.com/jsref/dom_obj_select.asp[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900