'selectedIndex' Example : selectedIndex « Javascript Properties « JavaScript Reference

Home
JavaScript Reference
1.Event Handlers Reference
2.Javascript Collections
3.Javascript Methods
4.Javascript Objects
5.Javascript Properties
JavaScript Reference » Javascript Properties » selectedIndex 
'selectedIndex' Example

    
<html>
<body>
<script>
function function1(colors) {
    var col = (colors.options[colors.selectedIndex].value);
    if (col) {
        document.bgColor = col; 
    
    alert("SelectedIndex value = "+col)

</script>
<form method="post" action="">
<select name="colors" onChange="function1(this);">
    <option value="white" selected>White</option>
    <option value="cyan">Cyan</option>
    <option value="ivory">Ivory</option>
    <option id="myO" value="blue">Blue</option>
    <option value="red">Red</option>
    <option value="lightblue">Lightblue</option>
    <option value="beige">Beige</option>
</select>
</form>

    
      
      
Related examples in the same category
1.'selectedIndex' Syntax and Note
2.'selectedIndex' is applied to
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.