JAVASCRIPT - What am I doing incorrectly?
Posted
by
DarkLightA
on Stack Overflow
See other posts from Stack Overflow
or by DarkLightA
Published on 2010-12-30T08:46:29Z
Indexed on
2010/12/30
8:54 UTC
Read the original article
Hit count: 255
LIVE CODE: http://jsfiddle.net/vy4nY/
I'm following this challenge, but I'm having some issues. I'm trying to make the Email Address box only appear when the checkbox is clicked on. What have I done incorrectly?
<!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>
<style type="text/css">
#emailpara {visibility:hidden;}
</style>
</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>
<script type="text/javascript">
document.getElementById('subscribe').onclick = (document.getElementById('subscribe').checked ? (document.getElementById('emailpara').style.visibility = 'visible') : (document.getElementById('emailpara').style.visibility = 'hidden'));
</script>
</body>
</html>
© Stack Overflow or respective owner