Skip to main content
November 14, 2006
Question

greying out part of a form

  • November 14, 2006
  • 6 replies
  • 444 views
I have a form which I have developed which has 4 parts to it.

Basically If a person selects the checkbox in part one then the greyed out section in Part 4 will become active and the checkbox in this area can be checked.

Parts 2 and 3 will always be active.

I'm just wondering how I can do this.

Thanks in advance for feedback.

Peter

    This topic has been closed for replies.

    6 replies

    Inspiring
    November 14, 2006
    You could also add a check to see what the value of that 4th check box is when you disable it too, if you want to make sure it's 'unchecked' when you do.
    Inspiring
    November 14, 2006
    Ok....quick and nasty version, but you'll get the idea.....

    <script type="text/javascript" language="javascript">
    function enable_disable()
    {
    var box4 = document.getElementById("chkTest4");
    if(box4.disabled == true)
    {
    box4.disabled = false;
    }
    else
    {
    box4.disabled = true;
    }
    }
    </script>

    <form action="#cgi.script_name#" method="post" name="frmTest">
    <input id="chkTest1" name="chkTest1" type="checkbox" value="1" onClick="enable_disable()"> Checkbox 1<br />
    <input id="chkTest2" name="chkTest2" type="checkbox" value="1"> Checkbox 2<br />
    <input id="chkTest3" name="chkTest3" type="checkbox" value="1"> Checkbox 3<br />
    <input id="chkTest4" name="chkTest4" type="checkbox" value="1"> Checkbox 4<br />
    </form>
    November 14, 2006
    wondering if anyone has an example - it would be great if someone could show an example and also some sample code.
    November 14, 2006
    Or you could use IF statements to enable or disable certain fields ... but JavaScript is probably better.
    Inspiring
    November 14, 2006
    Sorry.....probably should have expanded on that. Use the onClick event of your checkbox to fire a javascript function that enables/disables the other checkboxes you want to control.
    Inspiring
    November 14, 2006
    Javascript is your friend on this one.