PDA

View Full Version : Activate check box after text entry



Bornfree
05-26-2009, 11:02 PM
Hi Guys,

I wish to know if i can achieve this or not. I want to only activate a check box(with only 1 option) only after a text in entered in a particular box in a form!

Can this be done? If yes can someone please show me the way

forum_amnesiac
05-27-2009, 07:40 AM
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.


<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%">&nbsp;</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%">&nbsp;</td>
<td width="25%">&nbsp;</td>
<td width="1%">&nbsp;</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

Bornfree
05-31-2009, 09:45 PM
Thanks for you suggestion, but unfortunately what i want is slightly different!

I want to set up a form where an option for price request should only become active (Check Box) when a user enters any company name! the company name can be any text!

Sort of ! as soon as a word is entered in the box, the second check box optiuon should become active (otherwise it should be de-active)

traq
06-01-2009, 02:11 AM
Thanks for you suggestion, but unfortunately what i want is slightly different!

I want to set up a form where an option for price request should only become active (Check Box) when a user enters any company name! the company name can be any text!

Sort of ! as soon as a word is entered in the box, the second check box optiuon should become active (otherwise it should be de-active)

You forgot ! that last exclamation ! point ! :p j/k

This might work for what you need: Form Dependency Manager (http://www.dynamicdrive.com/dynamicindex16/formdependency.htm)

forum_amnesiac
06-01-2009, 12:52 PM
I've just noticed that I put a typo in my post, I should have said that the type of input is "unimportant" not important.

The code I've posted hides an input field until there is an entry in an input field that requires the hidden field to appear.

It is in fact a "dependency" input script.

Sorry about any confusion that my typo may have caused