?
Solved

Multiple Checkbox or listbox select

Posted on 2004-03-22
5
Medium Priority
?
2,328 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
[X]
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
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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
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 position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
Suggested Courses

770 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