473,569 Members | 2,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="JavaS cript">
function selectAllCheckB ox()
{ //alert(document. addzone.c1.valu e);
document.addzon e.c1.value = "on";
}
</script>

<P><input type="checkbox" name="c1">
<P><input type="button" onclick="select AllCheckBox()">
any ideas??
Jul 19 '05 #1
4 8403
document.addzon e.c1.checked = true

--
Roji. P. Thomas
--------------------------------------
"Matt" <ma*******@hotm ail.com> wrote in message
news:Om******** ******@TK2MSFTN GP11.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="JavaS cript">
function selectAllCheckB ox()
{ //alert(document. addzone.c1.valu e);
document.addzon e.c1.value = "on";
}
</script>

<P><input type="checkbox" name="c1">
<P><input type="button" onclick="select AllCheckBox()">
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="JavaS cript">
: function selectAllCheckB ox()
: { //alert(document. addzone.c1.valu e);
: document.addzon e.c1.value = "on";
: }
: </script>
:
: <P><input type="checkbox" name="c1">
: <P><input type="button" onclick="select AllCheckBox()">

1. language= on client-side is deprecated. Use type="text/javascript"
instead.
2. document.addzon e.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="select AllCheckBox()">
</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.addzon e.c1.checked=tr ue;

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 selectAllCheckB ox() {
var formCol='', elCol='';
formCol = document.forms['addzone'];
elCol = formCol.c1;
for(i=0;i<elCol .length;i++) {
elCol(i).checke d=true;
}
}
</script>
</head>
<body>
<form id="addzone" name="addzone">
<input type="checkbox" id="chk1" name="c1" value="1">One<b r />
<input type="checkbox" id="chk2" name="c1" value="2">Two<b r />
<input type="checkbox" id="chk3" name="c1" value="3">Three <br />
<input type="button" value="Check All Boxes" onclick="select AllCheckBox()">
</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
dsouzap
2 New Member
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="JavaS cript">
: function selectAllCheckB ox()
: { //alert(document. addzone.c1.valu e);
: document.addzon e.c1.value = "on";
: }
: </script>
:
: <P><input type="checkbox" name="c1">
: <P><input type="button" onclick="select AllCheckBox()">

1. language= on client-side is deprecated. Use type="text/javascript"
instead.
2. document.addzon e.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="select AllCheckBox()">
</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.addzon e.c1.checked=tr ue;

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 selectAllCheckB ox() {
var formCol='', elCol='';
formCol = document.forms['addzone'];
elCol = formCol.c1;
for(i=0;i<elCol .length;i++) {
elCol(i).checke d=true;
}
}
</script>
</head>
<body>
<form id="addzone" name="addzone">
<input type="checkbox" id="chk1" name="c1" value="1">One<b r />
<input type="checkbox" id="chk2" name="c1" value="2">Two<b r />
<input type="checkbox" id="chk3" name="c1" value="3">Three <br />
<input type="button" value="Check All Boxes" onclick="select AllCheckBox()">
</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
dsouzap
2 New Member
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
2881
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)) { $hasSubmittedUser = 0; $errorMsg .= $font . '<font color=cc0000><li>Could not insert record into db</li></font>' . '</font><p>';
7
2038
by: KJ | last post by:
What does this do: <xsl:apply-templates select="." /> ?
4
4959
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 keep getting errors thrown that I can't verify because the form processes onto itself too quickly for me to check the Javascript errors) because...
3
2446
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 underneath. Now, the rub here is that every checkbox on the page (except the "All"s)
10
5594
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 create a single View and specify also in this View the WHERE clause that is common in these stored procedures, I will have the new stored procecures...
2
5346
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 code below in the Web.Config file defines the authentication as forms and the aspx file required for login if the user is unauthenticated... this...
7
2891
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 JavaScript code, but the main problem I have is that checkboxes ids aren't kept when the datagrid is rendered, for example, if the checkboxes have...
5
7604
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
11678
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 checkboxes in the subform. At the moment I can disable/enable all textboxes, however my coding only checks/unchecks the FIRST checkbox in the subform, and...
0
7701
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7615
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8130
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.