473,434 Members | 1,486 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,434 software developers and data experts.

Select all the checkboxes using another checkbox

Hi guys tell me how to select all checkbox in single checkbox button
Aug 10 '07 #1
5 2186
ak1dnar
1,584 Expert 1GB
Moving threads from Articles to Forums

You have posted your question in the Articles section rather than the Forum section.I have moved it across for you.

Thanks please do not do the same again.
Aug 10 '07 #2
nathj
938 Expert 512MB
Hi guys tell me how to select all checkbox in single checkbox button
Hi niravmehtak,

This can be done I'm sure. What you need to do is set the value of all the other checkboxes on the clik of a controlling button.

I would do this using document.getElementById('checkbox').innerHTML.

So, on the controlling button you set the onclick() event to call a javascript function., into this function you can pass the ID's of the checkboxes you wish to set, then in a loop you can set the value to what it is not. So:

[html]
<form name="checkboxtest" action="target.html" methos="post>
<input type="checkbox" id="checkbox1" value="test1" />
<input type="checkbox" id="checkbox2" value="test2" />
<input type="checkbox" id="checkbox3" value="test3" />
<input type="checkbox" id="checkbox4" value="test4" />
<input type="button" id="checkboxAll" value="select all" onclick="selectAll('checkbox1, checkbox2, checkbox3, checkbox4', 'checkboxAll' />
</form>
[/html]

Then the javascript would look something like
Expand|Select|Wrap|Line Numbers
  1. function selectAll(pcChekcBoxList, pcControllingItem)
  2. {
  3. var laItems = pcCehckBoxList.split(',') 
  4. // creates an array
  5. lnArrayCntr = 0
  6. lnArrayLength = laItems.length - 1
  7. for(lnArrayCntr=0; lnArraycntr <= lnArrayLength; lnArrayCntr++)
  8. {
  9. if(document.getElementById(laItems[lnArrayCntr]).checked == "checked")
  10. {
  11. document.getElementById(laItems[lnArrayCntr]).checked = ""
  12. else
  13. {
  14. document.getElementById(laItems[lnArrayCntr]).checked = "checked"
  15. }
  16. if(document.getElementById(pcControllingItem).value == "Select All")
  17. {
  18. document.getElementById(pcControllingItem).value = "Unselect All"
  19. }
  20. else
  21. {
  22. document.getElementById(pcControllingItem).value = "Select All"
  23. }
  24. }
  25. }
  26.  
I haven't tested this, but the theory is correct and it should work. You may need to add some extra twiddles to set the button correctly. You could add an onclick to each checkbox that counts how many checkeboxes are checked. If it's all of them then set the button to "Unselect All", if it's not all of them then ensure that the button says "Select All". For this I would also use an array and a for loop.

That's my suggestion, I hope it helps. If you go to the nth degree, as I mention here this should work well in all circumstances.

Cheers
nathj
Aug 10 '07 #3
acoder
16,027 Expert Mod 8TB
Shouldn't this be in the Javascript forum (with a changed title)?

nathj, you could make it more generic. For example, see this example. Admittedly, that's probably more than what the OP needs, but no need to reinvent the wheel!
Aug 30 '07 #4
ak1dnar
1,584 Expert 1GB
Thread Title changed [Check box in php] to better describe the problem.
Moved from Php-Forum.Thanks.

@acoder:
Thanks for opening my eyes back to the thread.
Aug 30 '07 #5
acoder
16,027 Expert Mod 8TB
Thread Title changed [Check box in php] to better describe the problem.
Moved from Php-Forum.Thanks.

@acoder:
Thanks for opening my eyes back to the thread.
No problem. I only found it because it was linked to from another thread.
Aug 30 '07 #6

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

Similar topics

4
by: Matt | last post by:
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...
4
by: Michael Champagne | last post by:
We have an application to where you can select/deselect all checkboxes in a checkbox array by clicking a 'master' checkbox at the top of the screen. This seems to work fine unless there is only...
5
by: _andrea.l | last post by:
I have n checkboxes and 1 checkbox 'SELECT ALL'. for example: <form action="" method="get"> <input name="sa" type="checkbox" value="v"> select all <input name="c1" type="checkbox" value="v">...
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...
0
by: Peter Afonin | last post by:
Hello, I have 5 checkboxes in one record in the datagrid. When the user checks 5th checkbox (or, in my case, clicks the button - doesn't matter to me), all other checkboxes are checked as well....
7
by: rn5a | last post by:
The first column of a DataGrid has a CheckBox for all the rows. I want that when users check a CheckBox, the BackColor of that entire row in the DataGrid should change to a different color. To...
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....
4
by: allenpramod | last post by:
i am working with ms access. i got a problem with checkboxes. i create a checkbox in the form named chkbox with database fields.i am using continuous form so database fields are displayed with...
1
by: swebster | last post by:
Hi, I have a select all js function that works nicely but could use a little tweaking. I recently created a new form that includes hidden checkboxes using CSS that are made visible during a menu...
3
by: jmartmem | last post by:
Greetings, I have an ASP page containing a Record Insertion Form with a number of fields linked to an Access database. Within this form, I have a fieldset with six checkboxes, one of which is a...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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,...
1
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
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
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...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.