471,073 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

Multiple Checkbox Help Needed

I have a function that I call to check or uncheck all checkboxes on a
form - I use a 'master' checkbox to do this much like hotmail has to
check all mail messages - the code works fine if I name my checkboxes
like this:
chk1
chk1
chk1

But I need to name them with an array for deletion purposes which is
already coded and working - I need to name them like this:
chk[0]
chk[1]
chk[2]

I can't get the check/uncheck function to work with array checkbox
names - at the bottom of this I show my main checkbox I use to check
or uncheck all the others checkboxes named chk1 - but how do I pass
the name of the array checkboxes???
<!-- Hide javascript code
function check_checkboxes(pObj, pFlag)
{
if (pObj.length) {
for (var iCount=0; iCount<pObj.length; iCount++)
pObj [ iCount ].checked = pFlag;
}
else {
pObj.checked = pFlag;
}
}
// stop hiding javascript -->
</SCRIPT>

<INPUT TYPE="checkbox" NAME="frm_check_all"
onClick="check_checkboxes(document.pmsgs_form.chk1 ,
frm_check_all.checked)">Check/UnCheck All</TD>
Jul 20 '05 #1
2 8187

"Ralph Freshour" <ra***@primemail.com> schreef in bericht
news:dp********************************@4ax.com...

But I need to name them with an array for deletion purposes which is
already coded and working - I need to name them like this:
chk[0]
chk[1]
chk[2]

I can't get the check/uncheck function to work with array checkbox
names - at the bottom of this I show my main checkbox I use to check
or uncheck all the others checkboxes named chk1 - but how do I pass
the name of the array checkboxes???


<script type="text/javascript">
function check_checkboxes(pForm, pObj, pFlag) {
for (var iCount=0;;iCount++) {
if (!pForm.elements[pObj + iCount]) break;
pForm.elements[pObj + iCount ].checked = pFlag;
}
}
</script>

<form>
<input type="checkbox" name="chk0"><br />
<input type="checkbox" name="chk1"><br />
<input type="checkbox" name="chk2"><br />
<input type="checkbox" name="frm_check_all"
onclick="check_checkboxes(form,'chk',checked)">Che ck/UnCheck All
</form>
JW

Jul 20 '05 #2

"Janwillem Borleffs" <jw@jwscripts.com> schreef in bericht
news:3f***********************@news.euronet.nl...

But I need to name them with an array for deletion purposes which is
already coded and working - I need to name them like this:
chk[0]
chk[1]
chk[2]


Just realised that my previous solution did not work with PHP-array style
element names, the following does:

<script type="text/javascript">
function check_checkboxes(pForm, pObj, pFlag) {
var elem;
for (var iCount=0;;iCount++) {
elem = pObj + '[' + iCount + ']';
if (!pForm.elements[elem]) break;
pForm.elements[elem].checked = pFlag;
}
}
</script>

<form>
<input type="checkbox" name="chk[0]"><br />
<input type="checkbox" name="chk[1]"><br />
<input type="checkbox" name="chk[2]"><br />
<input type="checkbox" name="frm_check_all"
onclick="check_checkboxes(form,'chk',checked)">Che ck/UnCheck All
</form>

Also, have a look at the FAQ entry regarding this subject:

http://www.jibbering.com/faq/#FAQ4_25
JW

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Ralph Freshour | last post: by
3 posts views Thread by Voetleuce en f?nsievry | last post: by
8 posts views Thread by Ralph Freshour | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.