Forum Moderators: coopster & phranque

Message Too Old, No Replies

how to write onClick event for check box button to select all check bo

         

srins

4:01 pm on Oct 10, 2005 (gmt 0)

10+ Year Member



how to write java script, so that when i click "All" check button,it should select ,check all other buttons present.Here below is my code how I have defined checkboxes.how to include java script to select all checkboxes,by clicking "ALL" checkbox

#!/usr/local/bin/perl
use CGI;
$query = new CGI;
print $query->header();
$query->start_html(-title=>'Wow!',-script=>-language=>'JavaScript',
src=>'s.js');
print $query->h1('Wow!');
my %sample =(
component1=> ["command1", "command2"," command3"],
component2 => ["command1"," command2"," command3"],
);
while (($mykey, $myval) = each %sample)
{
push(@mykey, $mykey);
}
#print @mykey;
print $query->startform();
print $query->checkbox(-name=>"all",
-value=>'ALL',
-linebreak=>'true',
-onClick=>"checkAll(document.form.@mykey)"
);

foreach $key (keys %sample) {
foreach $i (0.. $#{$sample{$key}}){
print $query->checkbox_group(-name=>"$key",
values=>["@{$sample{$key}}[$i]"],
-linebreak=>'true',
-labels=>\%sample,
);
}
}
@turned_on = $query->param('$key');
print @turned_on;
print $query->endform;
$query->end_html();

KevinADC

8:18 pm on Oct 10, 2005 (gmt 0)

10+ Year Member



you could do it server side or client side. Which do you prefer?

srins

9:42 am on Oct 11, 2005 (gmt 0)

10+ Year Member



i need to do in serverside.

KevinADC

6:08 am on Oct 12, 2005 (gmt 0)

10+ Year Member



my $all = $query->param('all') ¦¦ 0;
if ($all) {
do whatever you need to
}

KevinADC

7:50 am on Oct 12, 2005 (gmt 0)

10+ Year Member



a feature of the CGI module is that form fields retain their value after you send the form data to the script. This means your "all" checkbox will remain checked when the page reloads. That's probably not what you want so use:

-override=>1

in the checkbox arguments