Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Howto Include JavaScript to CGI.pm Script

by misc (Pilgrim)
on Aug 28, 2007 at 10:09 UTC ( #635553=note: print w/ replies, xml ) Need Help??


in reply to Howto Include JavaScript to CGI.pm Script

Hello again,
you also didn't set the onClick attribute of '2 Fastest'.
I've modified the javascript slightly since you checked 2 Fastest by default. Clicking on any other checkbox will uncheck 2 Fastest now.

Depending on what you are going to do I'd possibly like to recommend some templating system like e.g. HTML::Template

For debugging javascript I use firebug with firefox. www.getfirebug.com

Greetings, michael

#!/usr/bin/perl -w use strict; use diagnostics; use Data::Dumper; use CGI qw/:standard :html3/; use CGI::Carp qw( fatalsToBrowser ); my $JSCRIPT=<<EOF; var twofastest; var checkboxes=[]; function initVars(){ if ( twofastest ) return; twofastest = document.getElementById('2 Fastest'); var cb = document.getElementsByName('progname'); var b = 0; for (var a=0; a<cb.length; a++ ){ if ( cb[a] != twofastest ){ checkboxes[b] = cb[a]; b++; } } } function checkBoxClick(){ initVars(); var anyboxchecked = false; for (var a=0; a<checkboxes.length; a++ ){ if ( checkboxes[a].checked ) anyboxchecked = true; } if ( anyboxchecked ) twofastest.checked = false; twofastest.disabled = anyboxchecked; } function twofastestClick(){ initVars(); for (var a=0; a<checkboxes.length; a++ ){ if ( twofastest.checked ) checkboxes[a].checked = false; checkboxes[a].disabled = twofastest.checked; } } EOF ; print header, start_html( -title => "Some Title", -script=> $JSCRIPT ); # some portions of code sub generate_form { print start_multipart_form(), #strong('Your email: '), #textfield( -name => 'user_email' ), br, br strong('Basic Programs To Choose: '), br checkbox_group( -name => 'progname', -values => [ '2 Fastest', 'MEME', 'MITRA', 'SPACE', ], -attributes=>{'2 Fastest'=>{'id'=>'2 Fastest', 'onClick'=>'two +fastestClick()'}, MEME=>{onClick=>'checkBoxClick()' }, MITRA=>{onClick=>'checkBoxClick()' }, SPACE=>{onClick=>'checkBoxClick()' } }, #the extra line added to print id -rows => '2', -columns => '6', -defaults => [ '2 Fastest' ], ), p, } generate_form(); print end_html();


Comment on Re: Howto Include JavaScript to CGI.pm Script
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://635553]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2014-08-22 01:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (145 votes), past polls