onChange Events

Certain types of form objects, such as checkboxes and menus can't have a text cursor, so they can't trigger an onBlur event when you make changes. You can use the onChange event to trigger your functions when the user has make his/her selection on these items.

<SCRIPT>
    function getSelect(s) {
        return s.options[s.selectedIndex].value
    }
</SCRIPT>

<FORM>
    <SELECT NAME="list" SIZE=1 onChange="location=getSelect(this)">
        <OPTION value="#"> Choose a search engine
        <OPTION value="http://www.yahoo.com"> Yahoo
        <OPTION value="http://www.lycos.com"> Lycos
        <OPTION value="http://www.excite.com"> Excit
     </SELECT>
<FORM>

Since Netscape forgot to provide a function for getting the value of a select box, I wrote one which I place in the <SCRIPT> tags of any page that has a selection list. Simply copy the getSelect(s) function into your <SCRIPT> area, and getSelect(form.mylist) will return the Value of the current mylist selection.

In this example we used the word this as a shortcut. We could have said getSelect(form.list), however since the command was inside the <SELECT> tag, the word this automatically referred to the current <SELECT> object. In this example, if Lycos was selected, then the event onChange="location=getSelect(this)" would be interpreted as location="http://www.lycos.com"


results matching ""

    No results matching ""