/    Sign up×
Community /Pin to ProfileBookmark

New at javascript, some help please

I have this code working but I can not figure out the last element. how do you get the “checkall” check box to be checked if all of the child check boxes are checked one at a time?

<html xmlns=”http://www.w3.org/1999/xhtml“>
<head runat=”server”>
<title>Untitled Page</title>
</head>
<script type=”text/javascript”>

function checkall(bu) {
var el, i=1;
while(el=document.getElementById(bu.id +(i++))) el.checked = bu.checked;
}
function checkall2(bu) {
var c = document.getElementById(bu.id.replace(/d/,””));
!bu.checked ? c.checked=false : null;

}
</script>
<body>
<form id=”form1″ runat=”server”>
<div>

<asp:CheckBox ID=”c” runat=”server” onclick=”checkall(this)”/>Check/Uncheck All

<input type=”checkbox” value=”” id=”c1″ onclick=”checkall2(this)”/>Abc
<input type=”checkbox” value=”” id=”c2″ onclick=”checkall2(this)”/>Def
<input type=”checkbox” value=”” id=”c3″ onclick=”checkall2(this)”/>Geh
<p>
<input type=”checkbox” value=”” id=”d” onclick=”checkall(this)”/>Check/Uncheck All
<input type=”checkbox” value=”” id=”d1″ onclick=”checkall2(this)”/>Ijk
<input type=”checkbox” value=”” id=”d2″ onclick=”checkall2(this)”/>Lmn
<input type=”checkbox” value=”” id=”d3″ onclick=”checkall2(this)”/>Opq
<p>
<input type=”checkbox” value=”” id=”e” onclick=”checkall(this)”/>Check/Uncheck All
<input type=”checkbox” value=”” id=”e1″ onclick=”checkall2(this)”/>Rst
<input type=”checkbox” value=”” id=”e2″ onclick=”checkall2(this)”/>Uvw
<input type=”checkbox” value=”” id=”e3″ onclick=”checkall2(this)”/>Xyz

</div>

</form>

</body>
</html>

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @dbeckett 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.17,
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,
)...