473,405 Members | 2,279 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,405 software developers and data experts.

implement "select all" button to select all checkboxes

In ASP page, there is a "SELECT ALL" button, when user click it, it will
select all checkboxes. I am not sure should I use client-side code to do
that? the following is my approach but it didnt work.

<script language="JavaScript">
function selectAllCheckBox()
{ //alert(document.addzone.c1.value);
document.addzone.c1.value = "on";
}
</script>

<P><input type="checkbox" name="c1">
<P><input type="button" onclick="selectAllCheckBox()">
any ideas??
Jul 19 '05 #1
4 8387
document.addzone.c1.checked = true

--
Roji. P. Thomas
--------------------------------------
"Matt" <ma*******@hotmail.com> wrote in message
news:Om**************@TK2MSFTNGP11.phx.gbl...
In ASP page, there is a "SELECT ALL" button, when user click it, it will
select all checkboxes. I am not sure should I use client-side code to do
that? the following is my approach but it didnt work.

<script language="JavaScript">
function selectAllCheckBox()
{ //alert(document.addzone.c1.value);
document.addzone.c1.value = "on";
}
</script>

<P><input type="checkbox" name="c1">
<P><input type="button" onclick="selectAllCheckBox()">
any ideas??

Jul 19 '05 #2
"Matt" wrote:
: In ASP page, there is a "SELECT ALL" button, when user click it, it will
: select all checkboxes.
That is not possible unless you pass the form on the URL or the header and
then test when the page is loaded. ASP is server-side.

: I am not sure should I use client-side code to do
: that?
You should.

: the following is my approach but it didnt work.
: <script language="JavaScript">
: function selectAllCheckBox()
: { //alert(document.addzone.c1.value);
: document.addzone.c1.value = "on";
: }
: </script>
:
: <P><input type="checkbox" name="c1">
: <P><input type="button" onclick="selectAllCheckBox()">

1. language= on client-side is deprecated. Use type="text/javascript"
instead.
2. document.addzone.c1.value = "on"; is not correct for three reasons.
a. addzone is not present. If you just didn't show that and have the
following then it is ok.

<form id="addzone" name="addzone">
<P><input type="checkbox" name="c1">
<P><input type="button" onclick="selectAllCheckBox()">
</form>

b. You do not have a value set for c1 so value="".
c. You do not test a value to see if a checkbox has been checked. This will
work:
document.addzone.c1.checked=true;

Also, you're only showing one checkbox. If you want a way to select all at
once, then you can use different IDs and name all of them the same name and
use it as an array.

<html>
<head>
<title></title>
<script type="text/javascript">
function selectAllCheckBox() {
var formCol='', elCol='';
formCol = document.forms['addzone'];
elCol = formCol.c1;
for(i=0;i<elCol.length;i++) {
elCol(i).checked=true;
}
}
</script>
</head>
<body>
<form id="addzone" name="addzone">
<input type="checkbox" id="chk1" name="c1" value="1">One<br />
<input type="checkbox" id="chk2" name="c1" value="2">Two<br />
<input type="checkbox" id="chk3" name="c1" value="3">Three<br />
<input type="button" value="Check All Boxes" onclick="selectAllCheckBox()">
</form>
</body>
</html>

Clean up:
<p> should have </p>
Your button should have a value.

--
Roland

This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.
-Technet Knowledge Base-
http://support.microsoft.com/default...&ln=EN-US&FR=0
-Technet Script Center-
http://www.microsoft.com/technet/tre...er/default.asp
-MSDN Library-
http://msdn.microsoft.com/library/default.asp
Jul 19 '05 #3
Hi Matt,


I used the solution for SelectAll for one of my ASp pages...it works great...but there is a problem when there is only one record (and hence only one check box) ....that one rec(check box) does not get checked at all... :( ....i even tried reworking on the loop and using the condition

if (elCol.length==0) ,...but no use...

please advise.


Regards
priya











"Matt" wrote:
: In ASP page, there is a "SELECT ALL" button, when user click it, it will
: select all checkboxes.
That is not possible unless you pass the form on the URL or the header and
then test when the page is loaded. ASP is server-side.

: I am not sure should I use client-side code to do
: that?
You should.

: the following is my approach but it didnt work.
: <script language="JavaScript">
: function selectAllCheckBox()
: { //alert(document.addzone.c1.value);
: document.addzone.c1.value = "on";
: }
: </script>
:
: <P><input type="checkbox" name="c1">
: <P><input type="button" onclick="selectAllCheckBox()">

1. language= on client-side is deprecated. Use type="text/javascript"
instead.
2. document.addzone.c1.value = "on"; is not correct for three reasons.
a. addzone is not present. If you just didn't show that and have the
following then it is ok.

<form id="addzone" name="addzone">
<P><input type="checkbox" name="c1">
<P><input type="button" onclick="selectAllCheckBox()">
</form>

b. You do not have a value set for c1 so value="".
c. You do not test a value to see if a checkbox has been checked. This will
work:
document.addzone.c1.checked=true;

Also, you're only showing one checkbox. If you want a way to select all at
once, then you can use different IDs and name all of them the same name and
use it as an array.

<html>
<head>
<title></title>
<script type="text/javascript">
function selectAllCheckBox() {
var formCol='', elCol='';
formCol = document.forms['addzone'];
elCol = formCol.c1;
for(i=0;i<elCol.length;i++) {
elCol(i).checked=true;
}
}
</script>
</head>
<body>
<form id="addzone" name="addzone">
<input type="checkbox" id="chk1" name="c1" value="1">One<br />
<input type="checkbox" id="chk2" name="c1" value="2">Two<br />
<input type="checkbox" id="chk3" name="c1" value="3">Three<br />
<input type="button" value="Check All Boxes" onclick="selectAllCheckBox()">
</form>
</body>
</html>

Clean up:
<p> should have </p>
Your button should have a value.

--
Roland

This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.
-Technet Knowledge Base-
http://support.microsoft.com/default...&ln=EN-US&FR=0
-Technet Script Center-
http://www.microsoft.com/technet/tre...er/default.asp
-MSDN Library-
http://msdn.microsoft.com/library/default.asp
Apr 25 '06 #4
Hi Roland

I used the solution for SelectAll for one of my ASp pages...it works great...but there is a problem when there is only one record (and hence only one check box) ....that one rec(check box) does not get checked at all... :( ....i even tried reworking on the loop and using the condition

if (elCol.length==0) ,...but no use...

please advise.


Regards
priya
Apr 25 '06 #5

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

Similar topics

3
by: Phil Powell | last post by:
$sql = 'INSERT INTO fs_usermetadata (' . substr(trim($cols), 0, strrpos(trim($cols), ',')) . ') VALUES (' . substr(trim($values), 0, strrpos(trim($values), ',')) . ')'; if (!mysql_query($sql))...
7
by: KJ | last post by:
What does this do: <xsl:apply-templates select="." /> ?
4
by: Phil Powell | last post by:
Has anyone here ever done a case where you have a select multiple form element and you have to do both server-side and client-side validation? I am honestly not sure how to do it in Javascript (I...
3
by: Adam Toline | last post by:
In reference to the following: http://www.bellecose.com/form.htm At the top of each column there is a box for "All". When one is checked I need to check all of (and only) those boxes...
10
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I...
2
by: Murphy | last post by:
Our website contains subdirectories for each subsidiary company, each company has it's own look and feel to the pages in their subdirectory although they are all part of the main website. The...
7
by: Jaime Stuardo | last post by:
Hi all.. I have a DataGrid with checkboxes. In the header I have a "check all" checkbox. I'm wondering if there is an easy way to check all checkboxes using that checkbox. I could do it using...
5
by: Lennart | last post by:
I really like the construction: select * from new table (update ....) X but I noticed that it cant be used as: insert into T select * from new table (update ....) X because of:
4
by: chengsi | last post by:
Hi, I have a "continuous" subform which is linked to a table which has a checkbox field. I would like to create a Check All/Uncheck All checkbox control that both checks and disables the...
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?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.