Jump to content

checkbox groups (*solved*)


Recommended Posts

Guest huey4657
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

<!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

<!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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.