473,545 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select All Checkbox

107 New Member
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 5675
Dormilich
8,658 Recognized Expert Moderator Expert
@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 New Member
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 Recognized Expert Moderator Expert
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
secmazec
34 New Member
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 Recognized Expert Expert
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 Recognized Expert Moderator Expert
@Markus
nevertheless, you may leave a note saying your page requires/operates best with JavaScript enabled.
Mar 20 '09 #7
secmazec
34 New Member
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 Recognized Expert Expert
@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
21160
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 value="cat">Cat <option value="dog">Dog ....
4
8401
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 work. <script language="JavaScript"> function selectAllCheckBox() { //alert(document.addzone.c1.value); document.addzone.c1.value = "on"; }...
4
6591
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 one checkbox (these are dynamically generated). Why does this fail? If I do an alert(field_to_check.length) with 1 element in the array like this I...
5
9562
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"> option 1 <input name="c2" type="checkbox" value="v"> option 2 <input name="c3" type="checkbox" value="v"> option 3 .... <input name="cn"...
0
1312
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. I've done it in SelectedIndexChanged event. My code is below. However, it takes too long to work on the server side. I'm sure it is possible to...
2
12816
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 Select list. This is what I tried. Any help is appreciated. ============== <script type="text/javascript"> function GetOptVal(OptVal)
0
3018
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 Checkbox Header Column 2-9: BoundField Column 10: img field If the user select one checkbox item, it will open up another gridview (multiple...
21
29746
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 prodcut anme have used ajax to avoid refreshing of page this works fine 2.now i have created one row with checkbox|select box|text|text|text|text|...
3
2986
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 "Select ALL" checkbox that selects or unselects all checkboxes in the fieldset. My problem is that when I select the "Select ALL" checkbox, it...
7
2164
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 category if checked with my checkbox ScreenShot: http://anthelo.org/errorSele.png Here is my code:
0
7398
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
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7805
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
7752
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...
1
5325
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4944
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
3441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1878
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
701
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.