When I try to call an Ajax function from a Javascript-generated pop up, it won't work..
# Perl CGI script: use myPackage; ### CGI Object ### my $cgi = new CGI; ### Ajax Object ### my $pjx = new CGI::Ajax( 'exported_func1' => \&exported_func1_code, 'exported_func2' => \&exported_func2_code, ); print $pjx->build_html($cgi, \&Show_HTML); sub exported_func1_code{ my $commentsobj = new myPackage(); ## some code that works.. (not package problem) ## this returns the data to "showContextMenu" ## and I can actually see the pop up.. $someHTML = " <!-- some HTML --> <input type=\"BUTTON\" id=\"SubmitId\" name=\"SubmitId\" VALUE +=\"Submit\" onClick=\"exported_func2(['CommentValue'],['dummyName']); +\"><center> <!-- some HTML --> "; return $someHTML; } sub exported_func2_code{ ## this one is called from inside the popupMenu ## but seems it cant be called from there..any suggestion? my ($p1,$p2,$p3,$p4) = split("\_",shift); my $commentsobj = new myPackage(); my $result = $commentsobj->myFunction($p1,$p2,$p3,$p4); return 1; } sub Show_HTML{ my $html_all = " <!-- headers.. --> <script type=\"text/javascript\"> function showContextMenu(input) { var menuContent = ''; menuContent = '<table width=100\%><tr><td>'+ input +'</td></tr +></table>'; var menuWidth = 400; var menuHeight = 400; var menuLeft = 200; var menuTop = 200; var popupMenu = parent.window.createPopup(); var popupMenuBody = popupMenu.document.body; popupMenuBody.style.border = 'solid black 1px'; popupMenuBody.style.fontSize = '2pt'; popupMenuBody.style.fontFamily = 'Arial'; popupMenuBody.innerHTML = menuContent; for (var i = 0; i < popupMenuBody.all.length; i++) { if(popupMenuBody.all[i].id == \"TextAreaId\"){ popupMenuBody.all[i].onkeypress = updateText; } } popupMenu.show(menuLeft, menuTop, menuWidth, menuHeight, docum +ent.body); return false; } function updateText(){ //var keypressedCode = e.keyCode || 1; //this does not work ! //var inputtext = String.fromCharCode(keypressedCode); //neith +er does this work ! this.value += 'HI'; } </scrip> <!-- more html.. --> <td onmouseover=\"exported_func1(['mySourceDivID'],[showCo +ntextMenu]);\">SomeText</td> <!-- more html.. --> "; return $html_all; }
The problem is that the code is able to call the "exported_func1_code" from the main page, but I'm not able to call the "exported_func2_code" from inside the pop up, any ideas? (it just tells me the script stopped running) Thanks ! EDIT: fixed code for exported_func2_code, sorry for the typo

In reply to Ajax function from js pop up by falpizar91

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.