The attachEvent MethodYou can use the attachEvent method to attach an event handler to an event in the Internet Explorer. This method returns true if the event handler was connected successfully. You can see the support for this method in Table 6.9. Table 6.9. The attachEvent Method
You pass this method the event to handle (as a string) and the handler function. We've already seen an example using the attachEvent method in the beginning of this chapter; in that example, I attached an event handler to a button's onclick event: <HTML> <HEAD> <TITLE>Using the attachEvent Method</TITLE> </HEAD> <BODY> <H1>Using the attachEvent Method</H1> <FORM NAME="form1"> <INPUT TYPE="BUTTON" NAME="button1" VALUE="Click Me!"> </FORM> <SCRIPT LANGUAGE="JavaScript"> <!-- document.form1.button1.attachEvent("onclick", alerter) function alerter() { alert("You clicked the button!") } // --> </SCRIPT> </BODY> </HTML> |