Hi guys tell me how to select all checkbox in single checkbox button
							
						
					Select all the checkboxes using another checkbox
				
					Collapse
				
			
		
	X
- 
	
	
	
		
	
	
	
		
	
	
	
	
	
	
	
	
	Tags: None
- 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 Hi niravmehtak,Originally posted by niravmehtakHi guys tell me how to select all checkbox in single checkbox button
 
 This can be done I'm sure. What you need to do is set the value of all the other checkboxes on the clik of a controlling button.
 
 I would do this using document.getEle mentById('check box').innerHTML .
 
 So, on the controlling button you set the onclick() event to call a javascript function., into this function you can pass the ID's of the checkboxes you wish to set, then in a loop you can set the value to what it is not. So:
 
 [html]
 <form name="checkboxt est" action="target. html" methos="post>
 <input type="checkbox" id="checkbox1" value="test1" />
 <input type="checkbox" id="checkbox2" value="test2" />
 <input type="checkbox" id="checkbox3" value="test3" />
 <input type="checkbox" id="checkbox4" value="test4" />
 <input type="button" id="checkboxAll " value="select all" onclick="select All('checkbox1, checkbox2, checkbox3, checkbox4', 'checkboxAll' />
 </form>
 [/html]
 
 Then the javascript would look something like
 I haven't tested this, but the theory is correct and it should work. You may need to add some extra twiddles to set the button correctly. You could add an onclick to each checkbox that counts how many checkeboxes are checked. If it's all of them then set the button to "Unselect All", if it's not all of them then ensure that the button says "Select All". For this I would also use an array and a for loop.Code:function selectAll(pcChekcBoxList, pcControllingItem) { var laItems = pcCehckBoxList.split(',') // creates an array lnArrayCntr = 0 lnArrayLength = laItems.length - 1 for(lnArrayCntr=0; lnArraycntr <= lnArrayLength; lnArrayCntr++) { if(document.getElementById(laItems[lnArrayCntr]).checked == "checked") { document.getElementById(laItems[lnArrayCntr]).checked = "" } else { document.getElementById(laItems[lnArrayCntr]).checked = "checked" } if(document.getElementById(pcControllingItem).value == "Select All") { document.getElementById(pcControllingItem).value = "Unselect All" } else { document.getElementById(pcControllingItem).value = "Select All" } } }
 
 That's my suggestion, I hope it helps. If you go to the nth degree, as I mention here this should work well in all circumstances.
 
 Cheers
 nathjComment
- 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 Shouldn't this be in the Javascript forum (with a changed title)?
 
 nathj, you could make it more generic. For example, see this example. Admittedly, that's probably more than what the OP needs, but no need to reinvent the wheel!Comment
- 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 No problem. I only found it because it was linked to from another thread.Originally posted by ajaxrandThread Title changed [Check box in php] to better describe the problem.
 Moved from Php-Forum.Thanks.
 
 @acoder:
 Thanks for opening my eyes back to the thread.Comment
Comment