Results 1 to 5 of 5

Thread: Activate check box after text entry

  1. #1
    Join Date
    Nov 2006
    Posts
    116
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Activate check box after text entry

    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

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    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%">&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

  3. #3
    Join Date
    Nov 2006
    Posts
    116
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    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)

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by Bornfree View Post
    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 ! j/k

    This might work for what you need: Form Dependency Manager

  5. #5
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •