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

Select All Checkbox

107 100+
I googled an found out only javascript doing the selecting of all checkbox in a form. Does that mean we there is no other ways to do it?

If only javascript can perform this operation, then how would it work to those who have disbled javascript. I avoid javascript most of the time, it is therefore i am looking for an alternative to perform the above cited operation. Please advise me!
Mar 20 '09 #1
8 5668
Dormilich
8,658 Expert Mod 8TB
@raamay
the description of your operation is a bit vague, maybe I can tell more with some additional details.
Mar 20 '09 #2
raamay
107 100+
I have a page displaying some records and each record accompanied with checkbox. So, if i want to delete certain records i can check those records using the checkbox and perform delete operation in one go using a button. In this similar fashion, i also want a control by which i can check all checkbox at one go and delete if necessary.
Mar 20 '09 #3
Dormilich
8,658 Expert Mod 8TB
since PHP is only executed on the server, user interactions are handled by Javascript.

To answer your question, there is no other way (as far as I see it).
Mar 20 '09 #4
It would be much easier for all if you either describe your problem better or paste some code.

First name checkboxes logically from 1...N, so you can go trough all of them easily, something like this, and store how many you have in PHP ($cb_sum in my example):
Expand|Select|Wrap|Line Numbers
  1. <input type="checkbox" name="option_1" value="Milk"> Milk<br>
  2. <input type="checkbox" name="option_2" value="Milk"> Milk<br>
  3. <input type="checkbox" name="option_3" value="Milk"> Milk<br>
  4.  
After the code, you need to store it in javascript, like:
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. var cb_sum = <? echo $cb_sum; ?>
  3. </script>
  4.  
And second part is really easy, you go from 1 to cb_sum in your javascript.

There is another way, if you need to have something like ID instead of 1..N in checkbox names, but that's more complicated.
Mar 20 '09 #5
Markus
6,050 Expert 4TB
You could use PHP to check all the boxes, if you are using PHP to generate the boxes and you don't mind a page refresh.

However, the amount of people not using javascript these days is incredibly small, and if they're not using it, it's their problem and not yours.
Mar 20 '09 #6
Dormilich
8,658 Expert Mod 8TB
@Markus
nevertheless, you may leave a note saying your page requires/operates best with JavaScript enabled.
Mar 20 '09 #7
actually if you only need it in PHP, that's very easy:

Expand|Select|Wrap|Line Numbers
  1. $selected = array ('a', 'b', 'c'); // list of selected ids
  2.  
  3. echo "<input type=\"checkbox\" ";
  4.  
  5. if($id==$selected)
  6. echo "checked "; // the magic :p
  7.  
  8. echo "value=\"$val\" name=\"$id\" id=\"$id\" />";
  9.  
N'joy

PS: JavaScript is client based, so it's function depends on their PC and Browser, not server. Hope I've helped ;)
Mar 20 '09 #8
Markus
6,050 Expert 4TB
@secmazec
Of course that would have to be in a loop, otherwise you're comparing $id against an array. ;) Alternatively, you could use in_array().
Mar 20 '09 #9

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

Similar topics

2
by: RC | last post by:
Order for PHP get the array from a HTML form checkbox or select tag. The HTML name MUST with . For example: <form methos=POST action="myfile.php"> <select name="pets" multiple> <option...
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">...
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....
2
by: bigrich | last post by:
I'm a beginner to javascript and need help. I've searched the forum but can't piece the answer together. I need to be able to uncheck and disable a checkbox based on the option selected in a...
0
by: New2ASP | last post by:
Thanks everyone in advance for your help. I am fairly new to web development but an experienced window-based developer. Here's the structure of my Gridview Column 1 : Checkbox with SelectAll...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
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...
7
by: avraamG13 | last post by:
Hello, I'm having a code that shows in a list checkbox and next the row name i have on my database I want to select a checkbox and when i press display to show me tha information of the specific...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.