Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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();

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://635553]
help
Chatterbox?
[Corion]: Last day at $work before 3 weeks of vacation (well, not that I'd be really travelling, but no-work-time ;) )
[robby_dobby]: marto: yeah, I'd eventually visit Glasgow some day - just to visit the home town of GHC :-)
[robby_dobby]: Corion: Oh, that's awesome! Your timing is perfect enough to see all hell break loose when you get back at work :P
[marto]: well, let me know in advance, I'll buy you a pint :)
[Corion]: robby_dobby: No, I'm returning in the second workweek of January. The main hectic parts are in the first days after the start of the new year
[robby_dobby]: marto: and, I'm not sure I'd be around here long enough for YAPC::EU
[marto]: Corion nice, what are you plans for Christmas?
[robby_dobby]: Corion: Nice, you just won't be around to deal with the mess - enjoy your vacation :-)
[robby_dobby]: marto: Sure, will do. Thanks!
[Corion]: marto: No great plans - I'll meet with my sister, my brother and my mother, but that's all :)

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2017-12-15 10:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (431 votes). Check out past polls.

    Notices?