Create a function to check the checkbox state and act accordingly:
Code JavaScript:
function checkMyBox(trigger,toggled){
var mcb = document.getElementById(trigger);
var cal = document.getElementById(toggled);
if(mcb.checked == false){
cal.style.display = 'none';
} else {
cal.style.display = 'block';
}
};
Use the body "onload" event to check initial state and the checkbox onclick event to react to user input.
HTML Code:
<body onload="checkMyBox('c2','div1')">
<form action="register-civ.php" method="post" name="go">
<input type="checkbox" name='c2' id="c2" value="check me 2" onclick="checkMyBox('c2','div1');">
<div id="div1">a calendar I have for the user</div>
<input name="submit" value="Submit" type="submit">
</form>
</body>
Also, as Cups suggested, the default state for the calendar should be visible, so that users without javascript can still use the form.
Bookmarks