/    Sign up×
Community /Pin to ProfileBookmark

check all checkbox fields

Hi,
I have this js code works perfectly in checking and un-checking the checkboxes.

[code=html]
<html>
<HEAD>
<script type=”text/javascript”>
<!–
function checkAll(checkname, exby) {
for (i = 0; i < checkname.length; i++)
checkname[i].checked = exby.checked? true:false
}
// –>
</script>
</HEAD>
<BODY>

<form name =”mylist”>
<input type=”checkbox” name=”checkGroup” value =”first”>First<br>
<input type=”checkbox” name=”checkGroup” value =”second”>Second<br>
<input type=”checkbox” name=”checkGroup” value =”third”>Third<br>
<input type=”checkbox” name=”checkGroup” value =”fourth”>Fourth<br>
<input type=”checkbox” name=”all” onClick=”checkAll(document.mylist.checkGroup,this)”>Check/Uncheck All<br>
</form>
</body>
</html>
[/code]

But i’m having problem in implementing it in my php code.
Because in my php i have my checkbox form variable is in array form
like this: multi_delete[]
so, how can make this script work ?
this is the php code

[code=php]
<form name =”mylist”>
<?php
//query here
while ($row = mysql_fetch_array($query)) {
$id = $row[‘id’];
echo “<input type=checkbox class=inputbordr name=’multi_delete[]’ value=’$id’><br>”;
}
echo “<input type=”checkbox” name=”all” onClick=”checkAll(document.mylist.multi_delete,this)”>Check/Uncheck All<br> “;
?>
</form>
[/code]

Thanks in advance

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsSep 09.2007 — [CODE]<html>
<HEAD>
<script type="text/javascript">
<!--
function checkAll(checkname, exby) {
var eles=exby.form.elements;
for (i = 0; i < eles.length; i++){
if (eles.name&&eles[i].name==checkname){
eles[i].checked = exby.checked? true:false;
}
}
}
// -->
</script>
</HEAD>
<BODY>

<form name ="mylist">
<input type="checkbox" name="checkGroup[]" value ="first">First<br>
<input type="checkbox" name="checkGroup[]" value ="second">Second<br>
<input type="checkbox" name="checkGroup[]" value ="third">Third<br>
<input type="checkbox" name="checkGroup[]" value ="fourth">Fourth<br>
<input type="checkbox" name="all" onClick="checkAll('checkGroup[]',this)">Check/Uncheck All<br>
</form>
</body>
</html>[/CODE]
Copy linkTweet thisAlerts:
@themoonauthorSep 10.2007 — Hi vwphillips ,

THanks for your input,

I have tried this code. Unfortunately, it didn't work.
Copy linkTweet thisAlerts:
@vwphillipsSep 10.2007 — oops

[CODE]<script type="text/javascript">
<!--
function checkAll(checkname, exby) {
var eles=exby.form.elements;
for (i = 0; i < eles.length; i++){
if (eles[i].name&&eles[i].name==checkname){
eles[i].checked = exby.checked? true:false;
}
}
}
// -->
</script>
[/CODE]
Copy linkTweet thisAlerts:
@themoonauthorSep 10.2007 — Thank you so much vwphillips

It works now.

M

?
×

Success!

Help @themoon 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...