begood321 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/local/bin/perl -w # restricts improper syntax and helps to debug error use strict; # require variables to be declared use diagnostics; # expand warnings (-w) expanation use CGI qw(:standard); # Include standard HTML and CGI +functions use CGI::Carp qw(fatalsToBrowser); # Send error messages to b +rowser my $JSCRIPT=<<EOF; function selectToggle(toggle, form) { var myForm = document.forms[form]; for( var i=0; i < myForm.length; i++ ) { if(toggle) { myForm.elements[i].checked = "checked"; } else { myForm.elements[i].checked = ""; } } } EOF my @availableCloningBranches = qw(test1 test2 test3 test4 test5); &printheader; if (param()) { &displayselections; } print "Select: "; print a( { href => "javascript:selectToggle(true, 'theForm');" + }, "All" ); print " | "; print a( { href => "javascript:selectToggle(false, 'theForm'); +" }, "None" ); &printform; &printtail; sub printheader { print header(), start_html(-title=>"MGI Cloning Tool Form", -bgcolor=>"#00CCFF", +-script=>$JSCRIPT), h1("MGI Cloning Tool Form"), hr; } sub printtail { print address("teamsiteadmin\@test.com"), end_html(); } sub printform { print h2("Copy pages, modules and components from current branch to +1 or more available branches below:"), start_form(), h4("Select Branches? "), checkbox_group(-name=>'branch', -values=>\@availableCloningBranches, -columns=>5, -multiple=>'true'), p, submit(-value=>"Submit form"), reset("Clear form"), end_form(); } sub displayselections { print h2("You have selected..."); print "<UL>"; foreach my $key (param) { my @values = param($key); print "<LI><B>$key:</B> "; print join(", ",@values),"</LI>\n"; } print "</UL><HR>"; }
Hello my fellow monks code above gives me no error with regards to javascript code.
However, select all or none doesn't toggle all checkboxes as it should.
I have used these 2 hyperlinks below as examples to construct my javascript code below which appears to work correctly.
http://www.randomsnippets.com/2008/02/28/javascript-to-select-all-or-none-of-the-checkboxes-in-a-form/
http://cpansearch.perl.org/src/MARKSTOS/CGI.pm-3.63/examples/javascript.cgi
Any help or suggestion is greatly appreciated, thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Javascript select and unselect all checkboxes not working in Perl CGI code
by soonix (Chancellor) on Jul 16, 2013 at 07:19 UTC | |
by begood321 (Novice) on Jul 16, 2013 at 13:59 UTC | |
by poj (Abbot) on Jul 16, 2013 at 14:09 UTC | |
by begood321 (Novice) on Jul 16, 2013 at 14:47 UTC | |
|
Re: Javascript select and unselect all checkboxes not working in Perl CGI code
by Anonymous Monk on Jul 16, 2013 at 03:14 UTC |