Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: CGI::AJAX onclick

by pc88mxer (Vicar)
on Jul 22, 2008 at 21:43 UTC ( #699436=note: print w/ replies, xml ) Need Help??


in reply to CGI::AJAX onclick

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; }


Comment on Re: CGI::AJAX onclick
Select or Download Code
Replies are listed 'Best First'.
Re^2: CGI::AJAX onclick
by Anonymous Monk on Jul 23, 2008 at 00:00 UTC
    So what I am doing is creating a link that when clicked loads a perl function, display, then through the same click passes a variable to a sub in perl. What this is for is when a user clicks a title of a post it expands then will query a sql server to display the content under the expanded title. So, the code you posted I would have to remove the text attribute and make that a href then have an onclick event assocate with it to load display, and to pass the variable to exported_func

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://699436]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (18)
As of 2015-07-07 17:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (92 votes), past polls