I need to display an extra field dynamically upon checking a checkbx on the page. I am using the following script and have got it to work fine. However, once the extra field is displayed, it does not disappear even if the checkbox is unchecked. I need to display an extra field only when the box is checked, and hide it when checkbox is unchecked. Can anyone help? Thanks a lot in advance.
===================
<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("temp","none");
changeDiv("test","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>
and in the body,
<form name="the_form">
<input type="Checkbox" name="temporary" onClick="hideAll(); changeDiv('temp','block');" value="temp"> Temporary check
<div id="temp" style="margin-left:100px;display:none">
<p><input type="text" name="testfield">
</div>
==========================
===================
<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("temp","none");
changeDiv("test","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>
and in the body,
<form name="the_form">
<input type="Checkbox" name="temporary" onClick="hideAll(); changeDiv('temp','block');" value="temp"> Temporary check
<div id="temp" style="margin-left:100px;display:none">
<p><input type="text" name="testfield">
</div>
==========================