I think we need to see more of your code. CGI::Ajax shouldn't define the Javascript function display() unless you have told it to handle that function in your constructor.
Update: I would also make sure that your JS attribute values have proper quotes around them, e.g. onclick="...". And, FWIW, this modification of the CGI::Ajax example program works for me - is this what you want to do?
#!/usr/bin/perl
use strict;
use CGI; # or any other CGI:: form handler/decoder
use CGI::Ajax;
my $cgi = new CGI;
my $pjx = new CGI::Ajax( 'exported_func' => \&perl_func );
print $pjx->build_html( $cgi, \&Show_HTML);
sub perl_func {
my $input = shift;
# do something with $input
my $output = $input . " was the input!";
return( $output );
}
sub Show_HTML {
my $html = <<EOHTML;
<HTML>
<HEAD>
<SCRIPT>
function display() { alert("I am in display") };
</SCRIPT>
</HEAD>
<BODY>
Enter something:
<input type="text" name="val1" id="val1"
onkeyup="exported_func( ['val1'], ['resultdiv'] );display(this)
+">
<button type=button onclick="display(this)">Click me!</button>
<br>
<div id="resultdiv"></div>
</BODY>
</HTML>
EOHTML
return $html;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|