Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript Checkbox Confirm

    Hello,

    I'm new to Javascript, but have been programming in PHP and other web codes for 4 years now.

    I was wondering how you would check if a checkbox was ticked, upon its selection and then unhide HTML content, and then hide such content when deselected..

    So far I have this:

    Code:
    <script type="text/javascript">
    	function Agree() {
    		document.getElementById("stepTwo").className = "";
    	}
    </script>
    Which is called by onclick="Agree()" on the select box itself..

    I understand an if statement is needed, but how would one go about doing this as my if statements do not appear to be working.

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,774
    Thanks
    55
    Thanked 518 Times in 515 Posts

    something like...

    Code:
    if (document.getElementById("mycheckbox").checked == true) {
    document.getElementById("stepTwo").style.display="inline";
    } else {
    document.getElementById("stepTwo").style.display="none";
    }


  •  

    Posting Permissions

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