Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I would like to add functionality to a separate button(s)/AJAX call that would come from a different form input, be associated to a separate Perl function, and direct its output to a different div

It's difficult to understand what you mean without a complete script so maybe this simple example will help.

#!/usr/bin/perl use strict; use CGI::Ajax; use CGI; my $cgi = new CGI(); my $pjx = new CGI::Ajax( 'function1' => \&myfunction1, 'function2' => \&myfunction2, # 'skip_header' => 1 ); print $pjx->build_html($cgi,\&main, {-charset=>'UTF-8', -expires=>'-1d'}); sub main { my $html = <<EOT; <HTML> <HEAD><title>CGI::Ajax Example</title></HEAD> <BODY> <div id="div1_text">Number = </div> <div id="div2_text">Letter = </div> <select id="select1" onchange="function1(['select1'],['div1_text'], +'POST'); "> <option value="">Select Number</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> <select id="select2" onchange="function2(['select2'],['div2_text'], +'POST'); "> <option value="">Select Letter</option> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> </select> </BODY> </HTML> EOT return $html; } sub myfunction1 { return "Number = ".shift }; sub myfunction2 { return "Letter = ".shift };
poj

In reply to Re: Using CGI::Ajax for multiple form buttons/divs simultaneously by poj
in thread Using CGI::Ajax for multiple form buttons/divs simultaneously by Polyglot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-28 18:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found