Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Howto Include JavaScript to CGI.pm Script

by misc (Friar)
on Aug 28, 2007 at 10:09 UTC ( [id://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();

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-19 19:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found