473,503 Members | 6,385 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check all checkboxes on clicking bottom checkbox

129 New Member
Hi friends,
I have a doubt about checkboxes, i.e if i am creating checkboxes with the same name, in a loop and i have another checkbox down to the above checkboxes, My problem is that if i select the down checkbox as a result the above checkboxes all to be checked(visible). Is it possible with the javascript.
Please help me my friends.
Dec 21 '07 #1
5 2375
gits
5,390 Recognized Expert Moderator Expert
hi ...

please post the code you have so far ... so that we might have an example to work with ...

kind regards
Dec 21 '07 #2
acoder
16,027 Recognized Expert Moderator MVP
Please remember to provide a meaningful Title for any threads started (see the FAQ entry Use a Good Thread Title).

This helps to ensure that other members, and also the general public, will have a better chance of finding answers to any similar questions.

MODERATOR
Dec 22 '07 #3
sasimca007
129 New Member
Expand|Select|Wrap|Line Numbers
  1. my $j = 1;
  2.         while(($u,$cha,$a) = $sth2->fetchrow_array())
  3.         {
  4. print <<HTML;
  5.         <tr style="color: blue"><td align="right"><input type="checkbox" name="$a" /></td><td align="center"><b>$j.</b></td><td align="center"><b>$cha</b></td><td></td><td align="center"><b>$a</b></td><td align="center">
  6. HTML
  7.         if($u eq $user_name)
  8.         {
  9. print <<HTML;
  10.         <input name = '$a' type="button" value="EDIT" onclick='disp(this.form,this.name)'>
  11.         </td><td align="center"><input name = '$a' type="button" value="DELETE" onclick='del(this.form,this.name)'></td></tr>
  12. HTML
  13.         }
  14.         else
  15.         {
  16. print <<HTML;
  17.         <input name = '$a' type="button" value="EDIT" onclick='display(this.form,this.name)'>
  18.         </td><td align="center"><input name = '$a' type="button" value="DELETE" onclick='ddisplay(this.form,this.name)'></td></tr>
  19. HTML
  20.         }
  21.             $j++;
  22.         }
  23. print <<HTML;
  24.     </table>
  25.     </center>
  26.     <br>
  27.     <center>
  28.     <table colspan=3 width="20%">
  29.         <tr>
  30.             <td align="center"><input type="checkbox" name="acheck"></td><td align="center"><input type="button" value="Add a New Comment" onclick='addevent(this.form)'></td><td align="center"><input type="button" onclick='next(this.form)' value="Authorize comments"></td>
  31.         </tr>
  32.         <tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr>
  33.     </table>
Dec 22 '07 #4
gits
5,390 Recognized Expert Moderator Expert
hi ...

have a look at the following example:

[HTML]<html>
<html>
<script type="text/javascript">
function check_all(abox) {
var table = document.getElementById('my_table');
var cboxes = table.getElementsByTagName('input');
var l = cboxes.length;

for (var i = 0; i < l; i++) {
var n = cboxes[i];
n.checked = abox.checked;
}
}
</script>
<body>
<table id="my_table">
<tr><td><input type="checkbox" name="cbox"/></td></tr>
<tr><td><input type="checkbox" name="cbox"/></td></tr>
<tr><td><input type="checkbox" name="cbox"/></td></tr>
</table>
check all
<input type="checkbox" name="chk_cbox" onclick="check_all(this);"/>
</body>
</html>[/HTML]
kind regards
Dec 22 '07 #5
acoder
16,027 Recognized Expert Moderator MVP
So, the one named "acheck" should check all the rest.

Add an onclick="checkAll(this.checked)". Now, in the checkAll function, you need to get all the checkboxes. You can get this using document.getElementsByTagName("input"). Then , you will need to check for the type that it's a checkbox. Set the checked property of each to the checked property of the main checkbox.

Edit: gits beat me to it with an example!
Dec 22 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
5965
by: Bob Bedford | last post by:
I create checkboxes using datas from a database (with PHP). I store all values in an array, as I must pass this value like a Form value. Now, in some cases, when a checkbox is selected, I must...
2
3214
by: jimi_xyz | last post by:
Sorry if this isn't the correct group, i don't think there is a group for straight HTML. I am trying to create a type of search engine. There are two radio buttons at the top, in the middle there...
2
27712
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
2237
by: .NETn00b | last post by:
Is this possible? I need to create a multi-select DataGrid, and I cannot use CheckBoxes. I want the selected rows to appear highlighted. One possible work-around that occurred to me was to...
10
5179
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....
1
4501
Frinavale
by: Frinavale | last post by:
I'm working on an ASP.NET application using VB.NET for server side code. I have a GridView listing a bunch of stuff. Above the GridView I have a checkbox named "ChkBx_SelectAll". If this...
4
3340
by: zufie | last post by:
I have two checkboxes on a form, ChckIBCCP and ChckOtherReferral. Each checkbox highlights its respective textboxes and combo boxes on the form. Many of the highlighted textboxes and combo...
3
3357
by: BibhuAshish | last post by:
Hi, I want to check or uncheck a number of checkboxes by clicking an image. My html code is given below: <TABLE> <TR> <TD>
13
3045
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...
0
7194
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
7070
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
7316
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...
1
6976
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
7449
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...
0
4666
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...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
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...

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.