Guest huey4657 Posted August 8, 2006 Share Posted August 8, 2006 Hi,Does anyone out there know how to check certain boxes within a group by calling ID instead of name?For example - all the checkboxes are named "name = Course[]" but to make them individual they have an id tag "ID = a, ID = b, etc...So I wish to either have a button or checkbox that controls some of the group. - "a, b, f, and y"Thks for any help or links. Link to comment https://forums.phpfreaks.com/topic/16949-checkbox-groups-solved/ Share on other sites More sharing options...
manmadareddy Posted August 9, 2006 Share Posted August 9, 2006 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE> New Document </TITLE><META NAME="Generator" CONTENT="EditPlus"><META NAME="Author" CONTENT=""><META NAME="Keywords" CONTENT=""><META NAME="Description" CONTENT=""><SCRIPT LANGUAGE="JavaScript"><!--function checkAll(obj){ var elements=document.getElementsByTagName("input"); var checkflag=obj.checked; for(var i=0;i<elements.length;i++) { if(elements[i].type=='checkbox') { if(elements[i].id.indexOf(obj.id)!='-1') { if(checkflag)elements[i].checked=true; else elements[i].checked=false; } } }}//--></SCRIPT></HEAD><BODY><FORM METHOD=POST ACTION=""><TABLE cellpadding=0 cellspacing=0 width='50%' border=1 ><TR> <TD><INPUT TYPE="checkbox" NAME="check[]" id='group1' onclick="checkAll(this);">Main group1</TD></TR><TR> <TD> <INPUT TYPE="checkbox" NAME="check[]" id='group1_1'>group11 <INPUT TYPE="checkbox" NAME="check[]" id='group1_2'>group12 <INPUT TYPE="checkbox" NAME="check[]" id='group1_3'>group13 <INPUT TYPE="checkbox" NAME="check[]" id='group1_4'>group14 </TD></TR><TR> <TD><INPUT TYPE="checkbox" NAME="check[]" id='group2' onclick="checkAll(this);">Main group2 </TD></TR><TR> <TD> <INPUT TYPE="checkbox" NAME="check[]" id='group2_1'>group21 <INPUT TYPE="checkbox" NAME="check[]" id='group2_2'>group22 <INPUT TYPE="checkbox" NAME="check[]" id='group2_3'>group23 <INPUT TYPE="checkbox" NAME="check[]" id='group2_4'>group24 </TD></TR></TABLE></FORM></BODY></HTML> Link to comment https://forums.phpfreaks.com/topic/16949-checkbox-groups-solved/#findComment-71637 Share on other sites More sharing options...
Guest huey4657 Posted August 9, 2006 Share Posted August 9, 2006 Sorry mate, your code doesn't work. It does not check any other box but itself. Link to comment https://forums.phpfreaks.com/topic/16949-checkbox-groups-solved/#findComment-71653 Share on other sites More sharing options...
manmadareddy Posted August 9, 2006 Share Posted August 9, 2006 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE> New Document </TITLE><META NAME="Generator" CONTENT="EditPlus"><META NAME="Author" CONTENT=""><META NAME="Keywords" CONTENT=""><META NAME="Description" CONTENT=""><SCRIPT LANGUAGE="JavaScript"><!--function checkAll(obj){ var elements=document.getElementsByTagName("input"); var checkflag=obj.checked; for(var i=0;i<elements.length;i++) { if(elements[i].type=='checkbox') { if(elements[i].id.indexOf(obj.id)!='-1') { if(checkflag)elements[i].checked=true; else elements[i].checked=false; } } }}//--></SCRIPT></HEAD><BODY><FORM METHOD=POST ACTION=""><TABLE cellpadding=0 cellspacing=0 width='50%' border=1 ><TR> <TD><INPUT TYPE="checkbox" NAME="check[]" id='group1' onclick="checkAll(this);">Main group1</TD></TR><TR> <TD> <INPUT TYPE="checkbox" NAME="check[]" id='group1_1'>group11 <INPUT TYPE="checkbox" NAME="check[]" id='group1_2'>group12 <INPUT TYPE="checkbox" NAME="check[]" id='group1_3'>group13 <INPUT TYPE="checkbox" NAME="check[]" id='group1_4'>group14 </TD></TR><TR> <TD><INPUT TYPE="checkbox" NAME="check[]" id='group2' onclick="checkAll(this);">Main group2 </TD></TR><TR> <TD> <INPUT TYPE="checkbox" NAME="check[]" id='group2_1'>group21 <INPUT TYPE="checkbox" NAME="check[]" id='group2_2'>group22 <INPUT TYPE="checkbox" NAME="check[]" id='group2_3'>group23 <INPUT TYPE="checkbox" NAME="check[]" id='group2_4'>group24 </TD></TR></TABLE></FORM></BODY></HTML> Link to comment https://forums.phpfreaks.com/topic/16949-checkbox-groups-solved/#findComment-71695 Share on other sites More sharing options...
Guest huey4657 Posted August 9, 2006 Share Posted August 9, 2006 Can anyone see where the problem is? I have changed things around but cannot seem to find why it does not work. ??? Can anyone tell me what this is doing - !='-1'thks for your help. Link to comment https://forums.phpfreaks.com/topic/16949-checkbox-groups-solved/#findComment-71697 Share on other sites More sharing options...
manmadareddy Posted August 9, 2006 Share Posted August 9, 2006 Hi Iam very sorry.I didn't saw the preview before posting.It is omitted all the indexes.Thats why its not working.Now U can check...[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE> New Document </TITLE><META NAME="Generator" CONTENT="EditPlus"><META NAME="Author" CONTENT=""><META NAME="Keywords" CONTENT=""><META NAME="Description" CONTENT=""><SCRIPT LANGUAGE="JavaScript"><!--function checkAll(obj){ var elements=document.getElementsByTagName("input"); var checkflag=obj.checked; for(var i=0;i<elements.length;i++) { if(elements[i].type=='checkbox') { if(elements[i].id.indexOf(obj.id)!='-1') { if(checkflag)elements[i].checked=true; else elements[i].checked=false; } } }}//--></SCRIPT></HEAD><BODY><FORM METHOD=POST ACTION=""><TABLE cellpadding=0 cellspacing=0 width='50%' border=1 ><TR> <TD><INPUT TYPE="checkbox" NAME="check[]" id='group1' onclick="checkAll(this);">Main group1</TD></TR><TR> <TD> <INPUT TYPE="checkbox" NAME="check[]" id='group1_1'>group11 <INPUT TYPE="checkbox" NAME="check[]" id='group1_2'>group12 <INPUT TYPE="checkbox" NAME="check[]" id='group1_3'>group13 <INPUT TYPE="checkbox" NAME="check[]" id='group1_4'>group14 </TD></TR><TR> <TD><INPUT TYPE="checkbox" NAME="check[]" id='group2' onclick="checkAll(this);">Main group2 </TD></TR><TR> <TD> <INPUT TYPE="checkbox" NAME="check[]" id='group2_1'>group21 <INPUT TYPE="checkbox" NAME="check[]" id='group2_2'>group22 <INPUT TYPE="checkbox" NAME="check[]" id='group2_3'>group23 <INPUT TYPE="checkbox" NAME="check[]" id='group2_4'>group24 </TD></TR></TABLE></FORM></BODY></HTML>[/code] Link to comment https://forums.phpfreaks.com/topic/16949-checkbox-groups-solved/#findComment-71698 Share on other sites More sharing options...
Guest huey4657 Posted August 9, 2006 Share Posted August 9, 2006 No need to be sorry, the help is much appreciated 'manmadareddy' thanks. ;D Link to comment https://forums.phpfreaks.com/topic/16949-checkbox-groups-solved/#findComment-71699 Share on other sites More sharing options...
Guest huey4657 Posted August 9, 2006 Share Posted August 9, 2006 I see if the input id's do not contain the obj.id string then indexOf returns '-1', clever. Link to comment https://forums.phpfreaks.com/topic/16949-checkbox-groups-solved/#findComment-71780 Share on other sites More sharing options...
manmadareddy Posted August 10, 2006 Share Posted August 10, 2006 just put one if condition like if(obj.id){ then......} Link to comment https://forums.phpfreaks.com/topic/16949-checkbox-groups-solved/#findComment-72290 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.