www.webdeveloper.com
Results 1 to 2 of 2

Thread: check box maximum checked issue

  1. #1
    Join Date
    Jul 2012
    Posts
    5

    check box maximum checked issue

    i have an issue getting an alert to work when checking a box when theres more than 10 categories selected. looked for previously solved issues on things similar to this but they dont seem to want to work.

    this is the div within the form that handles this particular checkbox.

    Code:
    <div class="form-item">
    					<label class="larger">* Main Areas of Expertise (Maximum of 10)</label>
    					<div class="checkholder">
    						<ul class="treeview">
    							<? foreach($skills as $skill){  $checked = (in_array($skill['UUID'],$selectedAreas)) ? TRUE : FALSE ; ?>
    								<? if($checked) { ?>
    									<li><label class="checkbox checked"><?=$skill['Name']?></label><input type="checkbox" checked="checked" name="skill[]" value="<?=$skill['UUID']?>" /></li>
    								<? } else { ?>
    									<li><label class="checkbox"><?=$skill['Name']?></label><input type="checkbox" name="skill[]" value="<?=$skill['UUID']?>" /></li>
    								<? } ?>
    							<? } ?>
    						</ul>
    					</div>
    				</div>
    if anyone can help would be much appreciaetd.

  2. #2
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,683
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
     <div class="form-item">
       <label class="larger">* Main Areas of Expertise (Maximum of 10)</label>
    	 <div class="checkholder">
    	  <ul class="treeview" id="tst" >
    	   <li><label class="checkbox checked">cb </label><input type="checkbox" checked="checked" name="skill[]" value="<?=$skill['UUID']?>" /></li>
    	   <li><label class="checkbox checked">cb </label><input type="checkbox" checked="checked" name="skill[]" value="<?=$skill['UUID']?>" /></li>
    	   <li><label class="checkbox checked">cb </label><input type="checkbox" checked="checked" name="skill[]" value="<?=$skill['UUID']?>" /></li>
    	   <li><label class="checkbox checked">cb </label><input type="checkbox" checked="checked" name="skill[]" value="<?=$skill['UUID']?>" /></li>
    	   <li><label class="checkbox checked">cb </label><input type="checkbox" checked="checked" name="skill[]" value="<?=$skill['UUID']?>" /></li>
    	   <li><label class="checkbox checked">cb </label><input type="checkbox" checked="checked" name="skill[]" value="<?=$skill['UUID']?>" /></li>
    	   <li><label class="checkbox checked">cb </label><input type="checkbox" checked="checked" name="skill[]" value="<?=$skill['UUID']?>" /></li>
    	   <li><label class="checkbox checked">cb </label><input type="checkbox" checked="checked" name="skill[]" value="<?=$skill['UUID']?>" /></li>
    	   <li><label class="checkbox checked">cb </label><input type="checkbox" checked="checked" name="skill[]" value="<?=$skill['UUID']?>" /></li>
    	   <li><label class="checkbox checked">cb </label><input type="checkbox" checked="checked" name="skill[]" value="<?=$skill['UUID']?>" /></li>
    	   <li><label class="checkbox checked">cb </label><input type="checkbox" checked="checked" name="skill[]" value="<?=$skill['UUID']?>" /></li>
    	   <li><label class="checkbox checked">cb </label><input type="checkbox" checked="checked" name="skill[]" value="<?=$skill['UUID']?>" /></li>
    	   <li><label class="checkbox checked">cb </label><input type="checkbox" checked="checked" name="skill[]" value="<?=$skill['UUID']?>" /></li>
    	  </ul>
    	</div>
      </div>
    
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function Max(id,max){
     var obj=document.getElementById(id),ips=obj.getElementsByTagName('INPUT'),ary=[],cnt=0,z0=0;
     for (;z0<ips.length;z0++){
      if (ips[z0].type=='checkbox'){
       ips[z0].onclick=function(){ CheckMax(this,ary,max); }
       ary.push(ips[z0]);
       if (ips[z0].checked){
        cnt++;
       }
       if (cnt>max){
        ips[z0].checked=false;
       }
      }
     }
    }
    
    function CheckMax(cb,ips,max){
     for (var cnt=0,z0=0;z0<ips.length;z0++){
       if (ips[z0].checked){
        cnt++;
       }
       if (cnt>max){
        cb.checked=false;
       }
    
     }
    }
    
    Max('tst',10)
    /*]]>*/
    </script>
    
    </body>
    
    </html>
    Vic

    God loves you and will never love you less.

    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

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