Solved

Passing variables between forms and interpreting values received in checkboxs

Posted on 2004-09-08
9
513 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
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 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding a countdown to HTA 12 111
Validating Date Part2 2 41
disable open new tab with right mouse click in <a> tag 3 38
Boolean 13 47
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

737 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