Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Multiple Checkbox or listbox select

Posted on 2004-03-22
5
2,307 Views
Last Modified: 2012-05-05
Hello,

I need to get the select of multiple checked checkboxes or from a listbox.  I would prefer checkbox so the user doesn't have to ctrl click each list box item.

<form action="test2.php" method="post">
<INPUT NAME="options" TYPE="CHECKBOX" VALUE="o1">
  Option 1<BR>
<INPUT NAME="options" TYPE="CHECKBOX" VALUE="o2">
  Option 2<BR>
<INPUT NAME="options" TYPE="CHECKBOX" VALUE="o3">
  Option 3<BR>
<INPUT NAME="options" TYPE="CHECKBOX" VALUE="o4">
  Option 4<BR>
<INPUT NAME="options" TYPE="CHECKBOX" VALUE="o5">
  Option 5<BR>
<INPUT NAME="options" TYPE="CHECKBOX" VALUE="o6">
  Option 6<BR>
<input type="submit">
</form>

I've tried the above form, but can only get the one lowest checkbox choice...so if checkbox 2 and 3 are checked, I can only get checkbox 3 choice.

Can anyone tell me where i'm going wrong please?

Cheers

RedRasper
0
Comment
Question by:RedRasper
5 Comments
 
LVL 10

Expert Comment

by:Bustarooms
ID: 10648597
you have named all the checkboxes "options"

give them unique names and each of the checkboxes states will be passed to test2.php
0
 

Author Comment

by:RedRasper
ID: 10648665
Sorry forgot to add,

I create the page dynamically, so I don't know how many check boxes there are going to be.  Is there any way to do this?

RedR
0
 
LVL 7

Expert Comment

by:gam3r_3xtr3m3
ID: 10648878
uhm... how dynamic? you should be able to change the names. =p
0
 
LVL 4

Accepted Solution

by:
g_damodar earned 125 total points
ID: 10648900
If you give the same name it will pass all the checked values to next page where the values are seperated by comma(,)

ex: if you select Option 1 ,Option 3 , Option 4
then you will get "01,03,04" in tthe next. So you need to split this string and read the values one by one

or
since i don't know the syntax in PHP I am giving the answer in ASP.

<form action="testmy.asp" method="get">
<INPUT NAME="options" TYPE="CHECKBOX" VALUE="o1">
  Option 1<BR>
<INPUT NAME="options" TYPE="CHECKBOX" VALUE="o2">
  Option 2<BR>
<INPUT NAME="options" TYPE="CHECKBOX" VALUE="o3">
  Option 3<BR>
<INPUT NAME="options" TYPE="CHECKBOX" VALUE="o4">
  Option 4<BR>
<INPUT NAME="options" TYPE="CHECKBOX" VALUE="o5">
  Option 5<BR>
<INPUT NAME="options" TYPE="CHECKBOX" VALUE="o6">
  Option 6<BR>
<input type="submit">
</form>

<%

      Response.write request("options").count
      Response.write("<BR>")
      for i=1 to request("options").count
            Response.write request("options")(i)
            Response.write ("<BR>")
      next
%>
0
 

Author Comment

by:RedRasper
ID: 10649664
Hi!

Thanks for the response, thats a nice asp result, and does work, unfortunatly it seems that php can't do the same, however I have now come up with a php solution which get around that!

Being name each option as option[] this forces php to create an array for it!

As g_damodar post helped me see a little light to get to my final result, I'll give the points to him/her if no one objects?

RedR
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
login jsp example 24 62
Scroll 5 news at a time. 4 33
Could I have some help for an easy CSS change to this latest news scroller 10 24
innerHTML 7 34
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question