Here's a function, with HTML example, I've used before that does what you want, although in this example it is for SELECT boxes, the type of input is important to the function.
It should be easily adapted for your needs.
HTML Code:
<script language="javascript" type="text/javascript">
<!--
function EnqFunc() {
if (document.getElementById("Enq_typ").options[document.getElementById("Enq_typ").selectedIndex].text=="Property") {
document.getElementById("property1").style.visibility='visible';
document.getElementById("property2").style.visibility='visible';
document.getElementById("lakes1").style.visibility ='hidden';
document.getElementById("lakes2").style.visibility ='hidden';
questionnaire.property.focus()
} else if (document.getElementById("Enq_typ").options[document.getElementById("Enq_typ").selectedIndex].text=="Lake") {
document.getElementById("property1").style.visibility='hidden';
document.getElementById("property2").style.visibility='hidden';
document.getElementById("lakes1").style.visibility ='visible';
document.getElementById("lakes2").style.visibility ='visible';
questionnaire.lakes.focus()
}
}
//-->
</script>
</head>
<body>
<form id="questionnaire" action="thanks.php" method="post" name="questionnaire">
<table width="100%" border="0">
<tr>
<td width="22%"><b>Type of Enquiry :</b></td>
<td width="25%"> <SELECT NAME="Enq_typ" id="Enq_typ" onchange="EnqFunc();">
<OPTION SELECTED> Property
<OPTION> Lake
</SELECT></td>
<td width="1%"> </td>
<td width="21%"><div style="visibility:hidden" id="property1"><b>Type of Property :</b></div></td>
<td width="31%"><div style="visibility:hidden" id="property2"><SELECT NAME="Property" id="property">
<OPTION SELECTED> House
<OPTION> Farm
<OPTION> Apartment
<OPTION> Building Land
<OPTION> Leaseback
</SELECT></div></td>
</tr>
<tr>
<td width="22%"> </td>
<td width="25%"> </td>
<td width="1%"> </td>
<td width="21%"><div style="visibility:hidden" id="lakes1"><b>Type of Lake :</b></div></td>
<td width="31%"><div style="visibility:hidden" id="lakes2"><SELECT NAME="Lakes" id="lakes">
<OPTION SELECTED> Existing Fishery
<OPTION> Fishery with House
<OPTION> Lake for Development
</SELECT></div></td>
</tr>
</table>
</form>
</body>
If there is an easier way for you then use that, but I've only ever done this using javascript
Bookmarks