SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Aug 2005
    Location
    Belgium
    Posts
    387
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    enable form with checkbox?

    Hello,

    I want a form to be only active when a box is checked.

    Now i found this code;
    Code:
    <script language="javascript">
    
    function enableField()
    {
    document.form1.address2.disabled=false;
    }
     
    </script>
    
    <input type="checkbox" name="vehicle" value="Bike" /> Acivate form.<br /><br />
    
    <a href="javascript:enableField()">Click here to enable the element<a/>
    And this does desactivate the rest of the form, but 1) when i click the link, nothing happens. and 2) I only want it to be activated when the first checkbox is cecked.

    To desiactivate you add (disabled="true") btw..

    Can someone help?


    Thanks!

  2. #2
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <script type="text/javascript">
    
    function enableField() {
    var inp = document.getElementById('address2');
    var el = document.getElementById('c1');
    if(el.checked) { inp.disabled=false; inp.focus(); }
    if(!el.checked) { inp.disabled=true;}
    }
    </script>
    
    <form>
    <input type="checkbox" id="c1" name="vehicle" value="Bike" onclick="enableField()" >Address: <input type="text" id="address2" disabled>
    </form>
    Last edited by muazzez; Jun 24, 2007 at 09:52.


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
  •