JavaScript Reference/Event Handlers Reference/onChange

Материал из Web эксперт
Перейти к: навигация, поиск

"onChange" Example

    
<head>
<script language="JavaScript">
    function function1(colors) {
        var col = (colors.options[colors.selectedIndex].value);
        if (col) { 
           document.bgColor = col; 
        }
        alert("The background color has changed to "+col) 
    } 
</script></head>
<body>
<select name="colors" onChange="function1(this)">
    <option value="white" selected>White</option>
    <option value="cyan">Cyan</option>
    <option value="ivory">Ivory</option>
</select>
</body>



"onChange" is applied to

+----------------+--------------------------------------------------------------+
| Applied_To     |<caption>                       <input type="text">           |
|                |<optgroup>                      <option>                      |
|                |<select>                        <textarea>                    |
+----------------+--------------------------------------------------------------+



"onChange" Properties

+----------------+--------------------------------------------------------------+
| Properties     |altKey                          altLeft                       |
|                |button                          clientX                       |
|                |clientY                         ctrlLeft                      |
|                |offsetX                         offsetY                       |
|                |returnValue                     screenX                       |
|                |screenY                         shiftKey                      |
|                |shiftLeft                       srcElement                    |
|                |type                            x                             |
|                |y                                                             |
+----------------+--------------------------------------------------------------+



"onChange" Syntax and Note

Note:
    
This event fires when the content of a form element is changed.