On 4/8/10 Thu  Apr 8, 2010  2:48 PM, "Ron Wingfield"
<ron.wingfi...@archaxis.net> scribbled:

> #!/usr/bin/perl -wT
> use strict;
> use warnings;
> use CGI;
> use CGI::Carp qw(fatalsToBrowser);
> my $q = new CGI;
> 
> sub whatever {
>     print "<p>Got into <b><i>\"whatever's\"</i></b> subroutine $_[0]</p>";
> }
> print $q->header,
>       $q->start_html( -title => "sub_test.pl");
> 
> @_ = "as a result of a non-conditional invocation; therefore, it IS defined.";
> &whatever;  # This non-conditional call works;
>             # therefore, the subroutine IS defined . . .somewhere.
> 
> print $q->button(
>       -name    => 'Say hello',
>       -onClick => 'alert("Hello!")'),   # . . .This works (try it!).
>       
>       $q->submit( -name    => 'whatever',
>                   -value   => '. . .click here for whatever',
>                   -onClick => 'whatever'); # . . .sucks air (:-(
>                  
> print ". . .and if you do, the the SOB complains that \"whatever\" is not
> defined.";       
> print "     <br><br>(Use Firefox with Error console opened . . .not MS/IE.)";
>                  
> print $q->end_html;

(Note: I deleted all of the comment lines in your program, as they don't add
to my understanding of your code.)

A CGI program like this executes on the server, normally as the result of a
form submission.

An "onClick" program executes in your browser when you click (in this case)
on the 'Say hello' button. Your browser is looking for a script called
'whatever' that was downloaded with the web page containing the button, not
a function in the CGI program sitting on the server. You need to include a
'whatever' function with the page containing the form for your browser to
execute, e.g. a Javascript method.



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to