View Single Post
  #1 (permalink)  
Old 08-01-2008, 11:59 AM
Lori Lori is offline
Registered User
 
Join Date: Aug 2008
Posts: 2
show/hide form fields

Hello,

I've created a form that has several checkboxes and then some questions related to the checkboxes. What I would like is for the related questions to be hidden until the checkbox is selected, then the addition questions for - that check box only - would appear. Is this something that can be done in javascript and can someone help me figure out how to build it?

Here's what I have so far:
<code>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Badgering</title>
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

//Hide div w/id extra
$("#extra").css("display","none");

// Add onclick handler to checkbox w/id checkme
$("#checkme").click(function(){

// If checked
if ($("#checkme").is(":checked"))
{
//show the hidden div
$("#extra").show("fast");
}
else
{
//otherwise, hide it
$("#extra").hide("fast");
}
});

});
</script>
<style type="text/css">
<!--
label {
display: block;
}
-->
</style>

</head>

<body>
<form>
<table>
<tr><td class=m><label for "Badgering">Badgering</label></td>
<td class=m><input type=checkbox size=10 name=_fid_12 />
<div id="extra">
<table>
<tr>
<td width="15"></td>
<td width="85">Timestamp(s)</td>
<td class="m" width="288"><input type="text" size="40" name="_fid_28"></td>
</tr>
</table>
</td>
</tr>
</div>
</table>
</form>
</body>


</html>
</code>

Thanks,
Lori

Last edited by Lori; 08-01-2008 at 01:47 PM. Reason: Adding code
Reply With Quote