The onclick Event


The onclick Event

As we know, the onclick event occurs when an object is clicked. You can find the support for this event in Table 6.61.

Table 6.61. The onclick Event

Event

NS2

NS3

NS4

NS6

IE3a

IE3b

IE4

IE5

IE5.5

IE6

onclick

x

x

x

x

x

x

x

x

x

x

Starting in Internet Explorer 4.0, virtually every visible object can have an onclick handler, which was much more than was available in Netscape Navigator 4.0 (which supported onclick for only the <INPUT> , <FORM> , <A> , and <SELECT> elements). Support for onclick is still limited in Netscape Navigator 6.0 compared to Internet Explorerfor example, <H1>-<H6> headers don't have an onclick event in the Netscape Navigator 6.0.

We've worked with the onclick event for a long time already; here's an example from Chapter 1 that displays an alert box when the user clicks a button (it's Listing 01-04.html on the web site):

 <HTML>      <HEAD>          <TITLE>              Executing Scripts in Response to User Action          </TITLE>  <SCRIPT LANGUAGE="JavaScript">   <!--   function alerter()   {   window.alert("You clicked the button!")   }   // -->   </SCRIPT>  </HEAD>      <BODY>          <H1>Executing Scripts in Response to User Action</H1>          <FORM>  <INPUT TYPE="BUTTON" ONCLICK="alerter()" VALUE="Click Me!">  </FORM>      </BODY>  </HTML> 

Tip

You can cancel the normal action connected to a click in the Internet Explorer by returning a value of false from the onclick event handler, or by setting window.event.returnValue to false in the event handler.




Inside Javascript
Inside JavaScript
ISBN: 0735712859
EAN: 2147483647
Year: 2005
Pages: 492
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net