Mar 26th, 2009, 9:12 AM
Dear Typer,
thanks for your replay. I use Javascript in similar way for unhidding child fields or making form more comfortable (moving to first incorrect filled field, validation or so).
I was just wonder if the system can do that automatically as I noticed that demo uses Java scripts for validation (but it works in pure php if Java is disabled).
thanks for your replay. I use Javascript in similar way for unhidding child fields or making form more comfortable (moving to first incorrect filled field, validation or so).
I was just wonder if the system can do that automatically as I noticed that demo uses Java scripts for validation (but it works in pure php if Java is disabled).
(Mar 26th, 2009, 8:42 AM)typer139 Wrote: Hey Nomad,
I'm not sure how this could be incorporated into the Formtools system itself, but I typically just handled it all through JavaScript. I've got a pretty intricate form that has tons of dependencies.. Here's some code I use on one field, i believe it's a dropdown but could be anything with a value. I typically fire this JavaScript "onChange" or "onClick" of the parent field.
I put DIV tags around field areas that will be shown/hidden and change their visibility based on the "parent" selection. In this code I also disable the box because I have a validation script that runs through all the fields on submit and it doesn't validate the "disabled" one's. (I found this out the hard was when the form never got submitted because all these "hidden" fields were still being validated and not passing)
Hope it works for you..
Rich Morgan
Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function showhide()
{
if(document.getElementById('do_you_smoke').checked == true)
{
document.getElementById('cig_brand_div').style.display = "block";
document.getElementById('cig_brand_dropdown').disabled = false;
}
else
{
document.getElementById('cig_brand_div').style.display = "none";
document.getElementById('cig_brand_dropdown').disabled = true;
}
}
</script>
</head>
<body>
<table width="250" border="0" cellspacing="0" cellpadding="5">
<tr>
<td>Check if You Smoke?</td>
<td><input name="do_you_smoke" type="checkbox" id="do_you_smoke" value="yes" onclick="showhide();" /></td>
</tr>
</table>
<br />
<div id="cig_brand_div" style="display:none;">
<table width="250" border="0" cellspacing="0" cellpadding="5">
<tr>
<td>What Brand?</td>
<td><select name="cig_brand_dropdown" id="cig_brand_dropdown">
<option value="Marlboro">Marlboro</option>
<option value="Other Brand">Other Brand</option>
<option value="Another Brand">Another Brand</option>
</select></td>
</tr>
</table>
</div>
</body>
</html>