EVENT:  onchange

onchange="action"
 
The onchange event occurs when a select input element has a selection made or when a text input element has a change in the text. Whenever the select or change occurs, the script code associated with the onselect event is executed. This script can call JavaScript functions which contain code that you want to run when the select occurs.
 
These six events are useful when dealing with forms and form elements:
 
  • onblur - runs a script when the element loses focus.
  • onchange - runs a script when the element changes.
  • onfocus - runs a script when the element gets the focus.
  • onreset - runs a script when the form is reset.
  • onselect - runs a script when the element is selected.
  • onsubmit - runs a script when the form is submitted.

  •  
    In this example, an alert message appears when a select is made.
     
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="eng">
    <head>
    <title>DevGuru XHTML onchange Example</title>
    </head>
    <body>
    <form>
    Please make a selection.
    <br />
    Note that an alert appears every time that you make a new selection.
    <p />
    <select onchange="JavaScript:alert('A new selection has been made')">
    <option>Angel fish</option>
    <option>Cat fish</option>
    <option>Discus</option>
    <option>Neon tetra</option>
    </select>
    </p>
    </form>
    </body>
    </html>

     
    Output:
    Click to view and test in separate window


    Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
    Trademark Information