473,714 Members | 3,153 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multiple checkbox

7 New Member
Hi

I have multiple checkboxes on my page and i want to access only the selected checkbox on the next page can any one give me the idea how to do it

Thnx in advance

Bye
Dec 11 '06 #1
35 76648
bishwadeep
12 New Member
Please see the following example. Hope it will help you
Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <form action="checkbox.php" method="post">
  3.   <input type="checkbox" name="checkbox" value="a">
  4.   <input type="checkbox" name="checkbox" value="b">
  5.   <input type="checkbox" name="checkbox" value="c">
  6.   <input type="checkbox" name="checkbox" value="d">
  7.   <br>
  8.   <br>
  9.   <input type="submit" name="Submit" value="Submit">
  10. </form>
  11. <?
  12.     if(isset($_POST['Submit']))
  13.     {
  14.         echo $_POST['checkbox'];
  15.     }
  16. ?>
  17. </body>
Dec 11 '06 #2
mudgilgaurav
7 New Member
Please see the following example. Hope it will help you
Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <form action="checkbox.php" method="post">
  3.   <input type="checkbox" name="checkbox" value="a">
  4.   <input type="checkbox" name="checkbox" value="b">
  5.   <input type="checkbox" name="checkbox" value="c">
  6.   <input type="checkbox" name="checkbox" value="d">
  7.   <br>
  8.   <br>
  9.   <input type="submit" name="Submit" value="Submit">
  10. </form>
  11. <?
  12.     if(isset($_POST['Submit']))
  13.     {
  14.         echo $_POST['checkbox'];
  15.     }
  16. ?>
  17. </body>
HI

Thnx for ur response
this thing know already i asked if i select 3 checkboxes on the first page then how to access all those three selected check boxes the method u gave print only the last selected box

if u know then plz reply

bye
Dec 11 '06 #3
ronverdonk
4,258 Recognized Expert Specialist
HI

Thnx for ur response
this thing know already i asked if i select 3 checkboxes on the first page then how to access all those three selected check boxes the method u gave print only the last selected box

if u know then plz reply

bye
This sample is incorrect! It treats the checkboxes like radio buttons because you give them all an identical name. And only one of the names can be set that way. When you want to get all the values that have been checked, you make the name field an array. So when you click checkboxes 1 and 3 (values 'a' and 'c'), you have an array that, when printed using print_r looks like:
Expand|Select|Wrap|Line Numbers
  1. Array ( 
  2.        [0] => a 
  3.        [1] => c 
  4.       ) 
So in your catching script you must process the array with name $_POST['checkbox']
Here is the code:
[php]<body>
<form action="checkbo x.php" method="post">
<input type="checkbox" name="checkbox[]" value="a">
<input type="checkbox" name="checkbox[]" value="b">
<input type="checkbox" name="checkbox[]" value="c">
<input type="checkbox" name="checkbox[]" value="d">
<br>
<br>
<input type="submit" name="Submit" value="Submit">
</form>
<?

/* and in your checkbox.php you do this: */

if(isset($_POST['Submit']))
{
for ($i=0; $i<count($_POST['checkbox']);$i++) {
echo "<br />value $i = ".$_POST['checkbox'][$i];
}
}
?>
</body>
[/php]
When you select boxes 2 and 4, the result of this script is then
Expand|Select|Wrap|Line Numbers
  1. value 0 = b
  2. value 1 = d
Ronald :cool:
Dec 11 '06 #4
crisis123
18 New Member
hi i have multiple checkboxes on my page and i wanna select only one at a time...i dont want to use radio buttons.

can anyone provide some help??

thanku
Jun 18 '09 #5
Dormilich
8,658 Recognized Expert Moderator Expert
but radio button would be best suited for that (i.e. they allow only one to be checked in a group)

anything beyond that requires JavaScript. (you can make it, so that you can select only one checkbox, but if the user disables JavaScript…)
Jun 18 '09 #6
crisis123
18 New Member
thanks a lot
well i had been askd to use the checkbox by the end user..thats why i had this problem.

another problem is that i have used <input type="checkbox" name="yes[]" value="Y"/> for creating the checkbox
but when i create a variable $checkbox=$_POS T['yes'] in my php script i get an error of undefined index
i have used post method to create the form

any suggestions?
Jun 18 '09 #7
crisis123
18 New Member
sorry i have used $checkbox=$_POS T['yes[]'] nd still encountered that undefined index error
Jun 18 '09 #8
Dormilich
8,658 Recognized Expert Moderator Expert
unchecked boxes (and radiobuttons) do not appear in $_POST.

do
Expand|Select|Wrap|Line Numbers
  1. var_dump($_POST);
to see what's present in the posted data.

you can also use isset() to check, if the variable/element exists.
Jun 18 '09 #9
crisis123
18 New Member
thanks a lot
i didnt know about the fact nd wasnt getting any info regarding it
Jun 18 '09 #10

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

Similar topics

2
8339
by: Ralph Freshour | last post by:
I have a function that I call to check or uncheck all checkboxes on a form - I use a 'master' checkbox to do this much like hotmail has to check all mail messages - the code works fine if I name my checkboxes like this: chk1 chk1 chk1 But I need to name them with an array for deletion purposes which is already coded and working - I need to name them like this:
12
2974
by: zig | last post by:
I've posted this on alt.comp.lang.coldfusion, but is predominantly a javascript problem: I have a CF query which returns several rows of records. I wanted to have a checkbox on each record of that returned query which would allow the user to select which record to print if checked. As the checkboxes are generated within the CF, they all have tha same name. With the help of a fellow a.c.l.c. member, we've got the script to a point...
4
13203
by: Vanessa | last post by:
I have an ASP script which is used to upload files with Persits.Upload.1 object. But I can't get the values from mutliple checkboxes in the form like normally. <form method="post" ENCTYPE="multipart/form-data"....> <input type="checkbox" name="language" value="English">English <input type="checkbox" name="language" value="Spanish">Spanish <input type="checkbox" name="language" value="Chinese">Chinese Please advice!
4
5476
by: ATDave | last post by:
So basically I'm just creating a form that I want the results e-mailed to somebody. I have everything working except for the checkmark sections that can have multiple answers. I'm a newbie when it comes to PHP, so please be easy :) So to show an example: <input type="checkbox" name="SelfDevelopmentInterest" class="other" value="Self Confidence" /> <label class="left">Self Confidence</label<br />
0
3116
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td colspan="2"><p>
16
3127
by: manius | last post by:
Hi. How do I insert in a db multiple checkbox results? I have 11 checkboxes, so how to do it in one query? Please :P
11
15282
by: TechnoAtif | last post by:
INSERT AND UPDATE MULTIPLE CHECKBOX DATA USING PHPMYSQL OR JAVASCRIPT Hi All I want to check the multiple checkboxes update them after revisiting that page. I am taking the name as name=type..in the form of array..but on checking it the result in the database simply gives the world 'array'.i want multiple checkboxes to be checked and updated simultaneously.. and the query to insert the checkbox value has to be included along with...
1
3457
by: infernodeep | last post by:
Hi, I have a dynamically generated form, and each listing contains a checkbox named 'del'. The users checks the 'del' checkbox next to each listing they wish to delete, and click the submit button. If there are multiple listings/checkboxes on the page, then the script I have works quite well, but if there is only one checkbox displayed on the page. If there is only one checkbox, and the user clicks the submit button, it still submits the...
0
1283
by: Mary arilene | last post by:
Hi, I currenlt building a form and would like some help validating multiple checkboxes and receiving values. I'm using two two pages there asp pages. HTML code(with the body tag) <tr bgcolor="#FFFFFF"> <td valign="top"><strong> How did you find out about us? </strong></td> <td align="left">
1
3797
by: Raywin | last post by:
Hello everyone, i am facing a problem with multiple checkbox. I have set few checkbox as a selection, then send to database for search result. For example the checkbox including hotel features like, aircont, 24 hour reception, swiming pool etc. after tick the check box , will send to result page to get the Hotel match with the selection checkbox. But my level only can make just one selection and get the result, if choose more than 1...
0
8810
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, 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...
0
9316
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9182
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9078
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,...
0
9026
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5959
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4466
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...
1
3160
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
2
2526
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.