Solved

Multiple Checkbox or listbox select

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
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 embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

785 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