In a pinch, I've put the javascript in a string (with a heredoc); printed it with the html header; and accessed it with onClick. Below is a simple example:
use strict; use CGI qw(:standard); my $js = <<"EOJS"; function someChecked(form) { var boxes = form.getElementsByTagName("input"); for (var i = 0; i < boxes.length; i++) { if (boxes[i].checked == true) return true; } alert("You didn't select any items to delete!"); return false; } EOJS print header, start_html( -TITLE => "My Title", -SCRIPT => {-code=>$js}), start_form, submit(-NAME=>"Page", -VALUE=>"Submit", -ONCLICK=>"return someChecked(this.form);"), checkbox("Test",'','ON','A'), checkbox("Test",'','ON','B'), end_form, end_html;
Update: Added checkboxes to make the example more sensible.
In reply to Re: Perl - calling javascript funciton
by hbm
in thread Perl - calling javascript funciton
by ax1lla
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |