473,379 Members | 1,190 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.

Check all form checkboxes funtion ??

The following html / javascript code produces a simple form with check
boxes. There is also a checkbox that 'checks all' form checkboxes
hotmail style:

<html>
<head>
<title></title>
</head>
<body>
<form name="myform" action=test.php method=post>
<script language="JavaScript">
<!--

var row_1 = new Array("Monday0", "Monday4")

function check_boxes1(state) { for (y=0; y < row_1.length; y++) {
for (i = 0; i < document.myform.elements.length; i++) {

if (document.myform.elements[i].name == row_1[i])
document.myform.elements[i].checked = state; }; }}
-->
</script>

<table><tr>
<td><input type=checkbox name=Monday0>Monday0</td>
<td><input type=checkbox name=Monday4>Monday4</td>
<td><input type="checkbox" name="checkall_row1"
onClick="check_boxes1(true)">toggle</td></tr>
<td><input type=submit value=submit class=button1></td>
</form>
</body>
</html>

I have no experience with javascript but assumed the below code would
allow me to create a similar form. This new form comprises of two rows
of check boxes with a row specific 'check all' checkbox at the end of
each row.
<html>
<head>
<title></title>
</head>
<body>
<form name="myform" action=test.php method=post>
<script language="JavaScript">
<!--

var row_1 = new Array("Monday0", "Monday4")

function check_boxes1(state) { for (y=0; y < row_1.length; y++) {
for (i = 0; i < document.myform.elements.length; i++) { if
(document.myform.elements[i].name == row_1[i])
document.myform.elements[i].checked = state; }; }}
var row_2 = new Array("Monday1", "Monday5")

function check_boxes2(state) { for (y=0; y < row_2.length; y++) {
for (i = 0; i < document.myform.elements.length; i++) { if
(document.myform.elements[i].name == row_2[i])
document.myform.elements[i].checked = state; }; }}

-->
</script>
<table>
<tr>
<td><input type=checkbox name=Monday0>Monday0</td>
<td><input type=checkbox name=Monday4>Monday4</td>
<td><input type="checkbox" name="checkall_row1"
onClick="check_boxes1(true)">toggle</td>
</tr><tr>
<td><input type=checkbox name=Monday1>Monday1</td>
<td><input type=checkbox name=Monday5>Monday5</td>
<td><input type="checkbox" name="checkall_row2"
onClick="check_boxes2(true)">toggle</td></tr>
<td><input type=submit value=submit class=button1></td>
</form>
</body>
</html>
Selecting row 1's 'check all' checks all check boxes in row 1
Selecting row 2's 'check all' doesn't check all check boxes in row 2.

Can anyone help me fix this?

Ta,

Ed
Jul 20 '05 #1
2 2408
Hello,

Replace in the two functions:
if (document.myform.elements[i].name == row_1[i]) with:
if (document.myform.elements[i].name == row_1[y])

Andif (document.myform.elements[i].name == row_2[i]) with:
if (document.myform.elements[i].name == row_2[y])

Guess you had a logic error in your for loop.

--
Elias
"Edward" <eg****@hotmail.com> wrote in message
news:58**************************@posting.google.c om... The following html / javascript code produces a simple form with check
boxes. There is also a checkbox that 'checks all' form checkboxes
hotmail style:

<html>
<head>
<title></title>
</head>
<body>
<form name="myform" action=test.php method=post>
<script language="JavaScript">
<!--

var row_1 = new Array("Monday0", "Monday4")

function check_boxes1(state) { for (y=0; y < row_1.length; y++) {
for (i = 0; i < document.myform.elements.length; i++) {

if (document.myform.elements[i].name == row_1[i])
document.myform.elements[i].checked = state; }; }}
-->
</script>

<table><tr>
<td><input type=checkbox name=Monday0>Monday0</td>
<td><input type=checkbox name=Monday4>Monday4</td>
<td><input type="checkbox" name="checkall_row1"
onClick="check_boxes1(true)">toggle</td></tr>
<td><input type=submit value=submit class=button1></td>
</form>
</body>
</html>

I have no experience with javascript but assumed the below code would
allow me to create a similar form. This new form comprises of two rows
of check boxes with a row specific 'check all' checkbox at the end of
each row.
<html>
<head>
<title></title>
</head>
<body>
<form name="myform" action=test.php method=post>
<script language="JavaScript">
<!--

var row_1 = new Array("Monday0", "Monday4")

function check_boxes1(state) { for (y=0; y < row_1.length; y++) {
for (i = 0; i < document.myform.elements.length; i++) { if
(document.myform.elements[i].name == row_1[i])
document.myform.elements[i].checked = state; }; }}
var row_2 = new Array("Monday1", "Monday5")

function check_boxes2(state) { for (y=0; y < row_2.length; y++) {
for (i = 0; i < document.myform.elements.length; i++) { if
(document.myform.elements[i].name == row_2[i])
document.myform.elements[i].checked = state; }; }}

-->
</script>
<table>
<tr>
<td><input type=checkbox name=Monday0>Monday0</td>
<td><input type=checkbox name=Monday4>Monday4</td>
<td><input type="checkbox" name="checkall_row1"
onClick="check_boxes1(true)">toggle</td>
</tr><tr>
<td><input type=checkbox name=Monday1>Monday1</td>
<td><input type=checkbox name=Monday5>Monday5</td>
<td><input type="checkbox" name="checkall_row2"
onClick="check_boxes2(true)">toggle</td></tr>
<td><input type=submit value=submit class=button1></td>
</form>
</body>
</html>
Selecting row 1's 'check all' checks all check boxes in row 1
Selecting row 2's 'check all' doesn't check all check boxes in row 2.

Can anyone help me fix this?

Ta,

Ed

Jul 20 '05 #2
@SM
Edward a ecrit :
There is also a checkbox that 'checks all' form checkboxes

<form name="myform" action=test.php method=post>
<couic>
<script language="JavaScript">
<!--

var row_1 = new Array("Monday0", "Monday4")

function check_boxes1(state) { for (y=0; y < row_1.length; y++) {
for (i = 0; i < document.myform.elements.length; i++) { if
(document.myform.elements[i].name == row_1[i])
document.myform.elements[i].checked = state; }; }}

var row_2 = new Array("Monday1", "Monday5")

function check_boxes2(state) { for (y=0; y < row_2.length; y++) {
for (i = 0; i < document.myform.elements.length; i++) { if
(document.myform.elements[i].name == row_2[i])
document.myform.elements[i].checked = state; }; }}

-->
</script>

<table>
<tr>
<td><input type=checkbox name=Monday0>Monday0</td>
<td><input type=checkbox name=Monday4>Monday4</td>
<td><input type="checkbox" name="checkall_row1"
onClick="check_boxes1(true)">toggle</td>
</tr><tr>
<td><input type=checkbox name=Monday1>Monday1</td>
<td><input type=checkbox name=Monday5>Monday5</td>
<td><input type="checkbox" name="checkall_row2"
onClick="check_boxes2(true)">toggle</td></tr>
<td><input type=submit value=submit class=button1></td>
</table>
</form>

Selecting row 1's 'check all' checks all check boxes in row 1
Selecting row 2's 'check all' doesn't check all check boxes in row 2.
it is only because when the function arrives on 2nd row
i = 3
but the 1st checkbox of this row is row_2[0]
i would be '0' .... and ... y has the correct value ! :-(
so :

function check_boxes2(state) {
for (y=0; y < row_2.length; y++)
for (i = 0; i < document.myform.elements.length; i++)
if(document.myform.elements[i].name == row_2[y]) // here the error
document.myform.elements[i].checked = state;
}
Can anyone help me fix this?


correct your 1st function like the new 2nd
--
************************************************** ************
Stéphane MORIAUX : mailto:st*********************@wanadoo.fr
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephanePOINTmoriaux/internet/
************************************************** ************
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Adrian Parker | last post by:
I have a PHP generated page which displays X many records. Each record has a checkbox preceding it. The user checks several checkboxes, and hits a delete button. All the corresponding records...
6
by: LRW | last post by:
I have no idea if this is more a PHP question or Javascript question, because my problem hinges equally on both. I have a PHP script that queries a database and creates a list of rows for each...
2
by: Travis.Box | last post by:
I have an MS Access userform with 16 Check Boxes. Each of the checkboxes has a different option value, which coincides with the Check Box name (eg. cb01.OptionValue = 1). At the bottom of the...
1
by: scprosportsman | last post by:
Please help guys, i am trying to set up a database here at work and im fairly new to access in terms of writing functions and queries and stuff. I have 2 different places on my design that will...
5
by: jimc52 | last post by:
Hello Everyone: I am hoping one of the gurus here will give me some help. I have designed a form with some check boxes. I put the checkboxes there on the form so later I could use them as flags on...
10
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked....
2
by: birwin | last post by:
I found a Javascript snippet that very effectively checks all boxes on a page, even on a page on which the input tags are in tables and on which I use a lot of other javascript. Unfortunately it is...
13
by: PhpCool | last post by:
Hi, since sometime I'm stuck in a problem where I want to check or uncheck all the checkboxes. If I'm choosing name for the checkbox array as 'chkbx_ary' then I'm able to check/uncheck all the...
1
by: Anuj | last post by:
Hi, since sometime I'm stuck in a problem where I want to check or uncheck all the checkboxes. If I'm choosing name for the checkbox array as 'chkbx_ary' then I'm able to check/uncheck all the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.