473,698 Members | 2,306 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 5684
8,658 Recognized Expert Moderator Expert
the description of your operation is a bit vague, maybe I can tell more with some additional details.
Mar 20 '09 #2
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
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
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>
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>
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
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
8,658 Recognized Expert Moderator Expert
nevertheless, you may leave a note saying your page requires/operates best with JavaScript enabled.
Mar 20 '09 #7
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
  3. echo "<input type=\"checkbox\" ";
  5. if($id==$selected)
  6. echo "checked "; // the magic :p
  8. echo "value=\"$val\" name=\"$id\" id=\"$id\" />";

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
6,050 Recognized Expert Expert
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

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 ....
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"; } </script>
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 get 'Undefined'. Is this because this datatype is not an array if there is only 1 element here? ...
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" type="checkbox" value="v"> option n </form>
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 do the same in Javascript. Unfortunatley, I don't know it that
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)
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 selection does nothing). If select a row item, it will open a different aspx page. If select...
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| where in the select box values are fetched from table here also i have used ajax for getting the m_name...
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 selects every checkbox in the form, not just those in the fieldset. Here is the code for the "Select...
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:
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
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
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.