First, I am not using jQuery, Catalyst, or similar tools because of their bloated nature. I require a bandwidth-efficient solution due to poor internet access among the primary clients of the web tool. AJAX has shown itself to work acceptably in my case with a single <div>, but I need more than one and have found no examples of such anywhere. Experimentation has yielded no success either.

Here's what I have that works:

my $cgi = new CGI; my $pjx = new CGI::Ajax( 'getBibCompare' => \&comparisonBible_function, 'skip_header' => 1, ); $pjx->skip_header(1); $pjx->cgi( $cgi ); print $pjx->build_html( $cgi, \&main, {-charset=>'UTF-8', -expires +=>'-1d'} ); $pjx->JSDEBUG(1); sub main { #. . . $html = &editScreen; return $html; } # END SUB main

Accompanied by the HTML…

<div> <h3>SCRIPTURE COMPARISON</h3> <div id="dcomparison_text" name="dncomparison_text" style="border: 1 +px solid gray; width:300px; min-height:150px; background-color: #ffff +cc"> $compare_verse </div> <div id="Bible_Version_Menu" name="nBible_Version_Menu"> <select id="comparison_text" name="ncomparison_text" onchange="getB +ibCompare(['comparison_text'],['dcomparison_text'], 'POST'); "> . . .

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>, as shown below.

my $cgi = new CGI; my $pjx = new CGI::Ajax( 'getBibCompare' => \&comparisonBible_function, 'processFormInputs' => \&processFormInputs, 'editScreen' => \&editScreen, 'skip_header' => 1, ); $pjx->skip_header(1); $pjx->cgi( $cgi ); print $pjx->build_html( $cgi, \&main, {-charset=>'UTF-8', -expires +=>'-1d'} ); $pjx->JSDEBUG(1);
With the HTML . . .
<div id="top_menu" name="ntop_menu" class="flex-container topnav"> $TOP_MENU_OPTIONS </div> <select id="chapter" name="nchapter" onchange="processFormInputs(['boo +k'],['top_menu'], 'POST'); this.form.submit();"> <option value="">Chapter</option> $bookchaptercountoptions </select> <select id="verse" name="nverse" onchange="processFormInputs(['verse'] +,['top_menu'], 'POST'); this.form.submit();" /> <option value="">Verse</option> $chapterversecountoptions </select> <input type="submit" id="prev_verse" name="nprev_verse" value="<-- Pre +v Verse" $pv onclick="processFormInputs(['prev_verse'],['top_menu'], 'POST'); t +his.form.submit();" /> <input type="submit" id="next_verse" name="nnext_verse" value="Next Ve +rse -->" $nv onclick="processFormInputs(['next_verse'],['top_menu'], 'POST'); t +his.form.submit();" />

When I have managed to get any output from this at all to appear on the screen, it appears in the <div> for the comparison text, and not in the one for the menu as it should. (The menu is updating its own options based on queries to the database to populate the option lists.) Any ideas for how to proceed would be much appreciated.

Blessings,

~Polyglot~


In reply to 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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.