Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 30-06-2009, 08:31 AM   #1 (permalink)
In The Zone
 
Sridhar_Rao's Avatar
 
Join Date: Feb 2007
Posts: 353
Default Checkbox group in javascript & PHP


A series of checkbox elements are generated on the fly depending on the table contents and their number is unknown. The group of checkboxes are given the same name say name="chkb". I use the following code to toggle between select all and deselect all.
Code:
function check(cl){
	if(document.getElementById('c1').checked == true){
		for(i=0;i<cl.length;i++){
			cl[i].checked = true;
		}
	}else{
		for(i=0;i<cl.length;i++){
			cl[i].checked = false;
		}
	}
}
When the user submits, I'd like to know how many were checked. The same code can be tweaked for this purpose.

When the form is submitted only one checkbox value is available in $_POST array even if all are checked. This is probably because the checkbox group must be renamed differently such as name="chkb[]" and can be accessed later using
foreach($_POST['chkb'] as $cd)

If the checkboxes are named as chkb[], then the above javascript fails. How do I get around this problem?
__________________
Want to study M.Sc in any medical subjects? Read this www.microrao.com/msc.htm
Microx, a diagnostic microbiology laboratory software application www.labmicrox.com
Sridhar_Rao is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 05-07-2009, 01:19 PM   #2 (permalink)
Right Off the Assembly Line
 
adatapost's Avatar
 
Join Date: Jul 2009
Location: India/Gujarat/Mehsana
Posts: 14
Default Re: Checkbox group in javascript & PHP

Add Id attribute.
adatapost is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Sujeet
- by gforz
- by soumya

Advertisement




All times are GMT +5.5. The time now is 03:14 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2