#!/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


In reply to Javascript select and unselect all checkboxes not working in Perl CGI code by begood321

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.