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
    Jun 2003
    Location
    Brooklyn, NY
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    array of checkboxes to enable/disable

    Hi,

    I'm trying to make what must be a simple checkbox enable/disable script. I have six checkboxes in one table cell and two in another table cell that are disabled when the page loads. Whenever one of the top six is checked, the two disabled come to life. This much I seem to have. The problem: I want the function to work so that if none of the top six are checked the two disabled boxes go back to being disabled after becoming enabled from previous onclicks. The function variable x is the checkbox's id that I'm sending to the function when one of the six is clicked. Here's what I've got, thanks in advance for whoever can help me out:

    function toggler(x)

    {

    for (var i = 0; i < document.forms[0].length; i++)

    {

    if (document.frm.selects[x].checked)

    {

    document.frm.lineChoice.lc1.disabled = false;

    document.frm.lineChoice.lc2.disabled = false;

    }

    else

    {

    document.frm.lineChoice.lc1.disabled = true;

    document.frm.lineChoice.lc2.disabled = true;

    }

    }

    }

  • #2
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    	<head>
    		<title>51508</title>
    		<!--[if IE]><script type="text/javascript">var ie = true;</script><![endif]-->
    	</head>
    	<body>
    		<form>
    			<fieldset id="controls">
    				<input type="checkbox">
    				<input type="checkbox">
    				<input type="checkbox">
    				<input type="checkbox">
    				<input type="checkbox">
    				<input type="checkbox">
    			</fieldset>
    
    			<fieldset id="toggles">
    				<input type="checkbox">
    				<input type="checkbox">
    			</fieldset>
    		</form>
    
    		<script type="text/javascript">
    			var controls = document.getElementById("controls").getElementsByTagName("input");
    			var toggles = document.getElementById("toggles").getElementsByTagName("input");
    
    			for(var i = 0; i < controls.length; i++)
    			{
    				if(!window.ie)
    				{
    					controls[i].addEventListener("click", toggle, true);
    				}
    				else
    				{
    					controls[i].onclick = toggle;
    				}
    			}
    
    			function toggle()
    			{
    				var checked = false;
    				var i = 0;
    
    				for(i = 0; i < controls.length; i++)
    				{
    					if(controls[i].checked == true)
    					{
    						checked = true;
    						break;
    					}
    				}
    
    				for(i = 0; i < toggles.length; i++)
    				{
    					toggles[i].disabled = !checked;
    				}
    			}
    
    			toggle();
    		</script>
    	</body>
    </html>


  •  

    Posting Permissions

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