Click here to Skip to main content
16,016,678 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a select control like this.
JavaScript
<script type="text/javascript">
        function countrychange() {
            var cou = document.getElementById('country').value;
            alert(cou);
        }
</script>


HTML
<select id="country" name="D1"  önchange="countrychange()">
        <option value="IN">India</option>
        <option value="US">USA</option>
</select>

When I change any country then it is displaying me it's value, but I want to display like this, suppose Option-India selected, then it should show me India.
Posted
Updated 9-Nov-11 2:51am
v2

are you familiar with Jquery..?
or Try this
JavaScript
var name=document.getElementById('country')[document.getElementById('country').nodeType].innerHTML
 
Share this answer
 
Comments
nhatnguyen124 9-Nov-11 23:24pm    
y
C#
var sel = document.getElementById('country');
var index = sel.selectedIndex;
var text = sel.options(index).text;
alert('the text is :'+ text + '\nthe value is : '+sel.value);
 
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