Passing variables between forms and interpreting values received in checkboxs

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


tedmcmasterAsked:
Who is Participating?
 
snoyes_jwConnect With a Mentor Commented:
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
 
alskdj80Connect With a Mentor Commented:
and in JSP, you would use Enumeration to get all the parameter names/values (which, in your case, would be the checkbox names)
0
 
COBOLdinosaurConnect With a Mentor Commented:
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
raj3060Connect With a Mentor Commented:
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
 
Neil_SimpsonCommented:
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
 
webwomanConnect With a Mentor Commented:
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
 
KarcOriginCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.