Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > implement "select all" button to select all checkboxes

Reply
Thread Tools

implement "select all" button to select all checkboxes

 
 
Matt
Guest
Posts: n/a
 
      01-11-2004
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??


 
Reply With Quote
 
 
 
 
Roji. P. Thomas
Guest
Posts: n/a
 
      01-11-2004
document.addzone.c1.checked = true

--
Roji. P. Thomas
--------------------------------------
"Matt" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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??
>
>



 
Reply With Quote
 
 
 
 
Roland Hall
Guest
Posts: n/a
 
      01-11-2004
"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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Submit button to select all items in a SELECT menu Gumtree Javascript 3 11-10-2004 01:45 PM
Select All Checkboxes Amit D.Shinde ASP General 1 07-07-2004 09:19 AM
select of select box will select multiple in another box palmiere Javascript 1 02-09-2004 01:11 PM
How to select all or deselect all checkboxes in datagrid... Al Knowles ASP .Net Datagrid Control 0 12-01-2003 06:22 PM
Datagrid Heading (Text - Clickable) and Row Elements (checkboxes) = Select All Feature BTHOMASinOHIO ASP .Net Datagrid Control 2 11-13-2003 10:54 PM



Advertisments