Solved

Passing variables between forms and interpreting values received in checkboxs

Posted on 2004-09-08
9
503 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
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now