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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkboxes (to receive all checked and concantenate values)

Status
Not open for further replies.

sisieko

Programmer
Jun 13, 2004
56
US
Hello friends,
It is my first time programming in cgi/perl, and i need to do a quick task.

I have 5 checkboxes for answer5.
I want to receive the checked values in my checkboxes (into an array) and concatenante them so that $answer5 will be received as e.g. "Trades Date / Pre-settlement / Archived" if ckbox 1, 2 and 5 are selected. Please guide me in the right path?

Code:
<input type=checkbox name='answer5' value="Trades Date">Trades Date
<input type=checkbox name='answer5' value="Pre-settlement">Pre-settlement
<input type=checkbox name='answer5' value="Up to one month">Up to one month &nbsp;
<input type=checkbox name='answer5' value="Up to 3 months">Up to 3 months &nbsp;
<input type=checkbox name='answer5' value="Archived">Archived

@answer5 = param('answer5');
foreach $ckbox5 (@answer5) {
....}

 
use CGI qw/:standard/;
my @answer5 = param('answer5');
my $string = join('/',@answer5);

Read up on the CGI module:


It's the standard for parsing form data with perl. Does lots of other handy stuff too.
 
Thanks Kevin :)

Now, how do i get my $string ($ckbox5) to collect this value. So that i can place it in a table field, so that $ckbox5 collects the values in the array like this $ckbox5 = "Trades Date / Pre-settlement / Archived".

Code:
my @answer5= param('answer5');
foreach $ckbox5 (@answer5)  {
$answer5 = join(' / ', @answer5);
	print qq|answer5|;
}

I tried this above, but it doesn't work :(

 
in the code I posted, just change $string to $ckbox5 and it should do what you want:

Code:
use CGI qw/:standard/;
my @answer5 = param('answer5');
my $ckbox5 = join(' / ',@answer5);
print $ckbox5;

@answer5 is an array that should already have all the values from the checked checkboxes named "answer5" in the form. There is no need to loop through that array to concatenate the values together, the join() function does that for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top