[an error occurred while processing this directive]
javascript tutorial graphic


Webteacher Software now offers

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 selec tion 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"> Excite
</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".

Check Boxes

Since a checkbox is selected/deselected with a mouse click, the onClick event will trigger your function whenever the checkbox is changed. Each checkbox has a property called checked which is equal to true or false depending on whether the box is currently checked. This example runs a function when the box is clicked, and displays a message if the box is checked.

function rushbox(checked) {
if (checked==true) {alert(" LIFT OFF! ")}
}
<FORM>
<INPUT TYPE=checkbox NAME="rush" OnClick="rushbox(form.rush.checked)"
Rush this order <FORM>
Rush this order

Page Load events

Home | WebData - Web Database Software | Javascript | CGI | Consulting | Map Builder | Contact Us | The Press Room