CGI::Ajax may be helpful. Here are a couple of quick examples to play around with. First is an example without javascript that prints to the page instead of a popup. (Update: More accurately said as "without having to write any javascript yourself", thanks almut)
#! /usr/bin/perl use strict; use warnings; use CGI; use CGI::Ajax; my $cgi = new CGI; my $pjx = new CGI::Ajax( 'exported_func' => \&too_many_nums ); print $pjx->build_html( $cgi, \&Show_HTML); sub too_many_nums { my $output = ""; my $input = shift; if( length($input) > 10 ) { $output = "Too many numbers!"; } return( $output ); } sub Show_HTML { my $html = <<EOHTML; <HTML> <BODY> Enter something: <input type="text" name="val1" id="val1" onkeyup="exported_fun +c( ['val1'], ['resultdiv'] );"> <br> <div id="resultdiv"></div> </BODY> </HTML> EOHTML return $html; }
And here is an example that uses a javascript popup.
#! /usr/bin/perl use strict; use warnings; use CGI; use CGI::Ajax; my $cgi = new CGI; my $pjx = new CGI::Ajax( 'exported_func' => \&too_many_nums ); print $pjx->build_html( $cgi, \&Show_HTML); sub too_many_nums { my $output = ""; my $input = shift; if( length($input) > 10 ) { $output = "Too many numbers!"; } return( $output ); } sub Show_HTML { my $html = <<EOHTML; <HTML> <BODY> <head> <script type="text/javascript"> function disp_alert() { var input = arguments[0] if( input != "" ) { alert(input); } } </script> </head> Enter something: <input type="text" name="val1" id="val1" onkeyup="exported_fun +c( ['val1'], [disp_alert] );"> <br> <div id="resultdiv"></div> </BODY> </HTML> EOHTML return $html; }
hth

In reply to Re: Create pop up error message in Perl by hominid
in thread Create pop up error message in Perl by Rocko19

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.