http://www.perlmonks.org?node_id=130225


in reply to Re: Why is my CGI.pm script trying to assign data before pressing submit.
in thread Why is my CGI.pm script trying to assign data before pressing submit.

With CGI.pm you would need these:

use CGI; my $p = new CGI; my $js_func = qq| function checkform (form) { if (form.report.value == '') { alert('You need to enter a filename!'); form.report.focus; return false; } return true; } |;

Place the script in $p->start_html using -script.

print $p->start_html( -script => $js_func );

Then, when you start the form, use:

print $p->start_form(-onsubmit => 'checkform(this)');


HTH,
Charles