473,379 Members | 1,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 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 8320

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ralph Freshour | last post by:
I'm using MySQL to display data on a web page - fitting about 10 records of data per screen - I'm including a checkbox with each record so that I can check it and when the submit button is clicked...
3
by: Voetleuce en f?nsievry | last post by:
G'day I'm looking for a script that can search multiple instances of Google (or other search engines optionally). The user types in a single word in the text field, presses ENTER or the submit...
8
by: Ralph Freshour | last post by:
I have multiple checkbox's created with an array name because I have many on the same web page - their names are like: frm_chk_delete frm_chk_delete frm_chk_delete frm_chk_delete etc. Here...
2
by: TonyM | last post by:
Hi Guys, I just need a push in the right direction here, I'm kinda stuck. I have a project with multiple Windows Forms launching from the main form by use of checkboxes. very easy, got that...
0
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
11
by: TechnoAtif | last post by:
INSERT AND UPDATE MULTIPLE CHECKBOX DATA USING PHPMYSQL OR JAVASCRIPT Hi All I want to check the multiple checkboxes update them after revisiting that page. I am taking the name as...
25
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section. ...
58
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
482
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place. ...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.