473,387 Members | 1,453 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,387 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 8321

"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
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.