Solved

Multiple Checkbox or listbox select

Posted on 2004-03-22
5
2,278 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now