javascript code to retrive a value and text from a dropdown list
<script>
function GetSelectedItem()
{
var z = document.getElementById("select1");
var x = z.options[z.selectedIndex].value;
var y = z.options[z.selectedIndex].text;
alert("selected value is "+x);
alert("selected text is "+y);
}
</script>
<div>
<select id="select1">
<option value="1">test1</option>
<option value="2">test2</option>
<option value="3">test3</option>
</select>
<br/>
<button onClick="GetSelectedItem();">Get Selected Item</button>
</div>
<script>
function GetSelectedItem()
{
var z = document.getElementById("select1");
var x = z.options[z.selectedIndex].value;
var y = z.options[z.selectedIndex].text;
alert("selected value is "+x);
alert("selected text is "+y);
}
</script>
<div>
<select id="select1">
<option value="1">test1</option>
<option value="2">test2</option>
<option value="3">test3</option>
</select>
<br/>
<button onClick="GetSelectedItem();">Get Selected Item</button>
</div>
No comments:
Post a Comment