Solved

Passing variables between forms and interpreting values received in checkboxs

Posted on 2004-09-08
9
512 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 100 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 100 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 100 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
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!

 
LVL 11

Assisted Solution

by:raj3060
raj3060 earned 100 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 100 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

Technology Partners: 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

Suggested Solutions

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

735 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