I'm simply trying to get an alert that is the result of checking a box. I can't seem to isolate the check-event. it fires when I load the page eventhough I try to set the check property to false initially.
Looking it up got me to jquery and all that stuff but for my formal training in javascript I need to stick to javascript and get this down first (jquery wil be my next course).
here's the code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>JavaScript Challenges</title>
<script type="text/javascript">
window.onload = function(){
checkbox = document.getElementById("subscribe");
checkbox.checked = false;
if (checkbox.checked = true){
alert("checked works");
}
}
</script>
</head>
<body>
<form action="">
<fieldset>
<legend>Email subscriptions</legend>
<p id="subscribepara">
<label>
<input type="checkbox" name="subscribe" id="subscribe">
Yes! I would like to receive the occasional newsletter via email.
</label>
</p>
<p id="emailpara">
<label>
Email Address:
<input type="text" name="email" id="email">
</label>
</p>
</fieldset>
</form>
</body>
</html>
it's a javascript challenge from wikiversity btw. second part of the first challenge. first part where you need Hiding the email element with style.display ='none' worked fine.