/    Sign up×
Community /Pin to ProfileBookmark

Mutliple Selected checkboxes

I’ve got a page, which is gerenated dynamically (php) with which I want the user to be able to do the following:
The table outputed is grouped into sections. The user can either select individual items via each individual items checkbox, or select the group by clicking the group checkbox.

I can’t work out how to as it were group the checkboxes. I can do it that it selects all, but that defeats the object!

Any help gratefully received.

Thanks
Nunners

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@jalarieSep 19.2006 — How about this:
<i>
</i> &lt;script type="text/javascript"&gt;
function DoGroup(Which) {
f1=document.forms[0]; // abbreviation
MainItem=f1[Which];
Match=new RegExp('^'+Which+'_.*$');
for (ix1=0; ix1&lt;f1.length; ix1++) {
SubItem=f1[ix1];
Type=SubItem.type;
if (Type == 'checkbox') {
Id=SubItem.id;
if (Id.match(Match)) {
if (MainItem.checked) {
f1[ix1].checked=true;
} else {
f1[ix1].checked=false;
}
}
}
}
} // DoGroup
&lt;/script&gt;

<i> </i> &lt;form action=""&gt;
<i> </i> &lt;table border="1" cellspacing="2" cellpadding="2"&gt;
<i> </i> &lt;tbody&gt;
<i> </i> &lt;tr&gt;&lt;td&gt;&lt;input type="checkbox" name="Group1" id="Group1" onchange="DoGroup('Group1');" /&gt;Group1&lt;/td&gt;&lt;/tr&gt;
<i> </i> &lt;tr&gt;&lt;td&gt;&lt;input type="checkbox" name="Group1_Item1" id="Group1_Item1" /&gt;&amp;nbsp;&amp;nbsp;Item1&lt;/td&gt;&lt;/tr&gt;
<i> </i> &lt;tr&gt;&lt;td&gt;&lt;input type="checkbox" name="Group1_Item2" id="Group1_Item2" /&gt;&amp;nbsp;&amp;nbsp;Item2&lt;/td&gt;&lt;/tr&gt;
<i> </i> &lt;tr&gt;&lt;td&gt;&lt;input type="checkbox" name="Group2" id="Group2" onchange="DoGroup('Group2');" /&gt;Group2&lt;/td&gt;&lt;/tr&gt;
<i> </i> &lt;tr&gt;&lt;td&gt;&lt;input type="checkbox" name="Group2_Item1" id="Group2_Item1" /&gt;&amp;nbsp;&amp;nbsp;Item1&lt;/td&gt;&lt;/tr&gt;
<i> </i> &lt;tr&gt;&lt;td&gt;&lt;input type="checkbox" name="Group2_Item2" id="Group2_Item2" /&gt;&amp;nbsp;&amp;nbsp;Item2&lt;/td&gt;&lt;/tr&gt;
<i> </i> &lt;/tbody&gt;
<i> </i> &lt;/table&gt;
<i> </i> &lt;/form&gt;
×

Success!

Help @Nunners spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...