?
Solved

Passing variables between forms and interpreting values received in checkboxs

Posted on 2004-09-08
9
Medium Priority
?
517 Views
Last Modified: 2012-05-05
If you select more than one checkbox in a form and then submit the results to another page, how are the individual results identified?? For example if I submit color selections:

Color = red
Color = white
Color = blue, and I only select red and blue and submit them. What is the mechanism that allows me to identify the colors I recieve on the new page. Is it an array?

I have several text on HTML and cannot see an answer or technique using this.

Thanks


0
Comment
Question by:tedmcmaster
[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
9 Comments
 
LVL 33

Accepted Solution

by:
snoyes_jw earned 400 total points
ID: 12008606
It may depend on what server side language you use to parse the form.  In PHP, you must name the checkboxes as color[], and then they will appear as an array in $_GET['color'] or $_POST['color'].  
0
 
LVL 3

Assisted Solution

by:alskdj80
alskdj80 earned 400 total points
ID: 12008622
and in JSP, you would use Enumeration to get all the parameter names/values (which, in your case, would be the checkbox names)
0
 
LVL 53

Assisted Solution

by:COBOLdinosaur
COBOLdinosaur earned 400 total points
ID: 12008662
Assuming the checkboxs are named Color then the url to the new page would include
Color=red,blue

This is the conventional method of processing arguments passed between pages

Processing a string of input variables in the format of
?id=5&key=2&x=32&Color=red,blue&other=x

<script type="text/javaScript">
<!--  
   parmarr = new Array;
   valuearr = new Array;
   colorarr = new Array
   function readparms()
   {
      if(location.search!='')
      {
         Args = location.search.substring(1);
         parmarr = Args.split('&');
         for(i=0;i<parmarr.length;i++)
         {
            valuearr[i] = parmarr[i].split('=');
            if (valuearr[i][0]=='Color') colorarr=valuearr[i][0].split(',');
         }
      }
   }
//-->
</script>

Cd&
0
Independent Software Vendors: 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!

 
LVL 11

Assisted Solution

by:raj3060
raj3060 earned 400 total points
ID: 12010786
How about using a dropdown, and allow multiple selections i.e.

<select name="COLOR" multiple="multiple">
<option value="RED">Red</option>
<option value="WHITE">White</option>
<option value="BLUE">Blue</option>
</select>

Now when you will read on next page, if you selected multiples then you will see

COLOR= RED,WHITE

--Raj
0
 
LVL 4

Expert Comment

by:Neil_Simpson
ID: 12010969
If you have used checkboxes then each should have a different name. The value passed to the next page will be something like ?red=true&white=&blue=true if form elements with the names red and blue and checked.
0
 
LVL 19

Assisted Solution

by:webwoman
webwoman earned 400 total points
ID: 12011135
Everybody is right. ;-)

Everything will depend on how you set the checkboxes up. If they have unique names, you'll get unique values. If they all have the same name, you'll get a set of values separated with commas. You would parse them according to how they were set up.

And of course, without seeing your form, or know how you set it up, we don't know what you did. If you used any of the WYSINWYG tools, it's very possible that you have ALL the checkboxes named the same -- even those that go with other questions. ;-)
0
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 12012379
Hi,

I am not sure but try to us ID tag and identify your control or submitted value by seeing this ID value.

Eg:

<INPUT type="checkbox" id="checkBox1" name="checkBox1" value="1">RED</TD>
<INPUT type="checkbox" id="checkBox2" name="checkBox1" value="1">GREEN</TD>
<INPUT type="checkbox" id="checkBox3" name="checkBox1" value="1">BLUE</TD>

Now even if the name is same your ID value will be different. On the posted form you can fetch ID by using.
Request.getParameterById(checkBox1")

Cheers and all the best!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
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)

762 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