Hi,
I am trying to explore the use of the 'addEventListener()' javascript event handler function. Below is the html/javascript code that I have written.
What I am trying to do is very simple... I am creating a form-input checkbox and display the alert "addEventListener Invoked !!" whenever the checkbox is clicked
The addeventlistener is supposed to monitor the checkbox for an 'onclick' event and display a alert pop-up whenever the checkbox is Clicked
What is happening is, when the html file with this code is opened in firefox or IE, the alert message is displayed immediately when the html page loads; and on clicking on the checkbox nothing happens :(
Now let me clarify, one might suggest to use the simple
onclick=alert("xyz")
event in the
<input type="checkbox" id="check"/>
tag....!! However, I want to implement this simple thing using addEventListener function...
So Gurus, it would be of great help if you can point out what is wrong with the below scrpit..
PS: I am a complete new bee in Javascript..
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"></meta>
<title>test</title>
</head>
<body><form>
<p>
<input type="checkbox" id="check" />
</p>
</form><script type="text/javascript">
document.getElementById("check").addEventListener("onclick",alert("addEventListner Invoked !!"), false)
</script></body>
</html>