Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forms

Status
Not open for further replies.

mike101

Programmer
Jul 20, 2001
169
US
Hey,
I have about 5 checkboxes on the page in a form. When it submits I want it to combine the checks. What I mean by that is say in the 5 checkboxes the values are "test" "hi" "cool" "whats" "up" and the name for all is "input" and "whats" and "up" are selected it will send it to the cgi script as file.cgi?input=whats,up currently it sends it as file.cgi?input=whats&input=up and I need it to somehow combine these to make that. Is there any way to do this? Thanks.
 
You might be able to use javascript to combine the values the way you want and put them in a hidden variable. Otherwise there's not much you can do about the ways the values are sent. The standard is to send the variable name and value multiple times if there is more than one field with the same name. How this is handled at the other end depends on how you get the form field values. I don't know how perl's CGI.pm does it, because I wrote my own routines to parse form variables. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
If you are using CGI.pm,

Code:
#!/usr/local/bin/perl
use CGI;
my $q = new CGI;
print $q->header, $q->start_html, $q->start_form;
print $q->checkbox_group(-name=>'
cb_group
Code:
',
                    -value=>['first','second','third']),
    '<br>',
    $q->submit;
[red]# the next line pulls the selected boxes into an array[/red]
Code:
@chks = $q->param('
cb_group
Code:
',');
foreach (@chks)
    {
    print &quot;<p>$_</p>\n&quot;;
    }
print $q->end_form, $q->end_html;

For more info on CGI.pm, do prompt# perldoc CGI <enter>

HTH

If you are new to Tek-Tips, please use descriptive titles, check the FAQs,
and beware the evil typo.
 
Not to be too picky, since you knew an answer to this one and I didn't, but I think there's something wrong with this line:
Code:
@chks = $q->param('cb_group',');
There's an odd number of apostrophes in there.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Tracy is absolutely correct. Sorry about that. I typed it but obviously did not run it. I hope I have not cost anyone to much time in debugging.

The line should look like,
Code:
@chks = $q->param('cb_group');

Tracy, thanks for the proofing.

If you are new to Tek-Tips, please use descriptive titles, check the FAQs,
and beware the evil typo.
 
De nada. I'd bet you've caught me in a typo or two as well. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top