www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] break doesnt just break out of a loop it breaks my whole code

Threaded View

  1. #1
    Join Date
    Jan 2012
    Posts
    34

    resolved [RESOLVED] break doesnt just break out of a loop it breaks my whole code

    In the below code i have a checkbox to select or deselect all. and then three options i can enable or disable.
    The idea is that if any of them go red the checkall box is unchecked. and if all of them have turned back green then it will be checked. everything works right up until the turning them back green part which i have commented out in the code below. when im turning things back on the 1st option is what breaks then no longer works as it should.
    here is the link with the section commented out
    http://www.elfpro3d.com/test/test_commented.php

    and here it is with the section put in and broken.
    http://www.elfpro3d.com/test/test_broken.php

    HTML Code:
    <?php
    if (isset($_POST['bob'])){if(!empty($_POST['emailto'])) {foreach ($_POST['emailto'] as $service) {echo "You selected: $service <br>";}}}
    ?>
    <html>
    <head>
    <script type="text/javascript">
    
    function emailDiv(gemch,gemdi){
    	if (document.getElementById(gemch).disabled != true){
    		document.getElementById(gemdi).style.backgroundColor="#C33";		        document.getElementById('emaildis').checked=false;
    		document.getElementById(gemch).disabled=true;
    		}
    	else{
    		document.getElementById(gemdi).style.backgroundColor="#0C6";
    		document.getElementById(gemch).disabled=false;
    		/*everything works untill i add this which is supposed to check if all are enabled if any are disabled do not turn on the check all checkbox and exit the loop
    		var assGo=document.getElementsByName("emailto[]");
    		for (i = 0; i < assGo.length; i++){
    			if (assGo[i].disabled = true){document.getElementById('emaildis').checked=false;break;}
    			else{document.getElementById('emaildis').checked=true;}
    			}*/
    		}	
    }
    function emailDis(){
    	var assGo=document.getElementsByName("emailto[]");
    	if (document.getElementById('emaildis').checked){
    		for (i = 0; i < assGo.length; i++){
    		assGo[i].disabled = false ;
    		document.getElementById('emailto'+i).style.backgroundColor="#0C6";
    		}
    		}
    	else {
    		for (i = 0; i < assGo.length; i++){
    		assGo[i].disabled = true ;
    		document.getElementById('emailto'+i).style.backgroundColor="#C33";
    		}
    		}	
    }
    </script>
    </head>
    <body>
    <form action="" method="post">
    <input style="background-color:#C33; float:left" type="checkbox" id="emaildis" onclick="emailDis()" checked="checked" />
    
    <div id="emailto0" style="margin:2px; border:1px solid #000; border-radius:5px; padding:4px; float:left; background-color:#0C6" onclick="emailDiv('getsemailch0','emailto0')">
    <span style="cursor:default; font-weight:bolder; font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#FFFFFF">Peter Piper</span>
    <input type="hidden" name="emailto[]" id="getsemailch0" value="peter@piper.com" /> 
    </div>
    
    <div id="emailto1" style="margin:2px; border:1px solid #000; border-radius:5px; padding:4px; float:left; background-color:#0C6" onclick="emailDiv('getsemailch1','emailto1')">
    <span style="cursor:default; font-weight:bolder; font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#FFFFFF">Bob Bobbins</span>
    <input type="hidden" name="emailto[]" id="getsemailch1" value="bob@bobland.bob" />
    </div>
    
    <div id="emailto2" style="margin:2px; border:1px solid #000; border-radius:5px; padding:4px; float:left; background-color:#0C6" onclick="emailDiv('getsemailch2','emailto2')">
    <span style="cursor:default; font-weight:bolder; font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#FFFFFF">Mary Maryland</span>
    <input type="hidden" name="emailto[]" id="getsemailch2" value="mary@contrary.hairy" />
    </div>
    
    <input type="submit" name="bob" value="click me" />
    </body>
    </html>
    Last edited by Da_Elf; 05-06-2013 at 10:26 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles