Some help with Javascript checkboxes

Discussion in 'JavaScript' started by Silvers, Sep 12, 2008.

  1. #1
    How do I make Javascript checkboxes than needs to be checked ?
    I have a site and I need something at the new user registration ( I agree with TOS ) and the TOS checkbox needs to be checked ...
    Hope you understand my request :p

    /edit : I found something related at DynamicDrive : http://www.dynamicdrive.com/dynamicindex16/acceptterm.htm
    It's not the same thing but it can do the job :D
     
    Silvers, Sep 12, 2008 IP
  2. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That's pretty simple actualy. Here's one way to do it:
    
    <script type='text/javascript'>
    function enableConfirm(checked)
    {
    	if(document.forms[0].check.checked == true)
    		document.forms[0].confirm.disabled = '';
    	else
    		document.forms[0].confirm.disabled = 'disabled';
    }
    </script>
    <form method='post'>
    <input type='checkbox' name='check' onclick='enableConfirm(this.checked)'>
    <input type='submit' name='confirm' disabled>
    </form>
    
    Code (markup):
     
    xlcho, Sep 13, 2008 IP
  3. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #3
    you can also use the document.getElementByID method

    function checkConfirm(chkID)
    {
    var chkBox = document.getElementById(chkID);
    return chkBox.checked
    }

    use it like this

    if( !checkConfirm('theCheckBoxID') )
    {
    alert('your error goes here');
    }
     
    serialCoder, Sep 14, 2008 IP