JB1981
03-03-2006, 02:35 PM
I've got some code to use checkboxes to make certain parts of a form apear, but I need to be able to hide those sections when the option is unchecked after it was checked. Im sure im 90% of the way there, but cant figure out the right way to do it.
Thanks for the help.
Example (http://www.allyvideo.com/testdm.htm)
<html><head><title></title>
<script type="text/javascript">
<!--
function changeDiv(the_div,the_change)
{
var the_style = getStyleObject(the_div);
if (the_style != false)
{
the_style.display = the_change;
}
}
function hideAll()
{
changeDiv("formsec1","none");
changeDiv("formsec2","none");
changeDiv("formsec3","none");
}
function getStyleObject(objectId) {
if (document.getElementById && document.getElementById(objectId)) {
return document.getElementById(objectId).style;
} else if (document.all && document.all(objectId)) {
return document.all(objectId).style;
} else {
return false;
}
}
// -->
</script>
</head>
<body>
<form name="the_form">
<h1>Please choose and fill out the following forms </h1>
<input type="checkbox" name="pet"
onClick="changeDiv('formsec1','block');">Fillout Section 1
<input type="checkbox" name="pet"
onClick="changeDiv('formsec2','block');">Fillout Section 2
<input type="checkbox" name="pet"
onClick="changeDiv('formsec3','block');">Fillout Section 3
<p>
<div id="formsec1" style="margin-left:30px;display:none">
FORM SECTION #1
</div>
<div id="formsec2" style="margin-left:30px;display:none;">
FORM SECTION #2
</div>
<div id="formsec3" style="margin-left:30px;display:none;">
FORM SECTION #3
</div>
</body>
</html>
Thanks for the help.
Example (http://www.allyvideo.com/testdm.htm)
<html><head><title></title>
<script type="text/javascript">
<!--
function changeDiv(the_div,the_change)
{
var the_style = getStyleObject(the_div);
if (the_style != false)
{
the_style.display = the_change;
}
}
function hideAll()
{
changeDiv("formsec1","none");
changeDiv("formsec2","none");
changeDiv("formsec3","none");
}
function getStyleObject(objectId) {
if (document.getElementById && document.getElementById(objectId)) {
return document.getElementById(objectId).style;
} else if (document.all && document.all(objectId)) {
return document.all(objectId).style;
} else {
return false;
}
}
// -->
</script>
</head>
<body>
<form name="the_form">
<h1>Please choose and fill out the following forms </h1>
<input type="checkbox" name="pet"
onClick="changeDiv('formsec1','block');">Fillout Section 1
<input type="checkbox" name="pet"
onClick="changeDiv('formsec2','block');">Fillout Section 2
<input type="checkbox" name="pet"
onClick="changeDiv('formsec3','block');">Fillout Section 3
<p>
<div id="formsec1" style="margin-left:30px;display:none">
FORM SECTION #1
</div>
<div id="formsec2" style="margin-left:30px;display:none;">
FORM SECTION #2
</div>
<div id="formsec3" style="margin-left:30px;display:none;">
FORM SECTION #3
</div>
</body>
</html>