Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Multiple Checkbox or listbox select

Posted on 2004-03-22
5
Medium Priority
?
2,337 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

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.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

610 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