Mercurial > boosterpack
annotate scripts/pjx_callback.pl @ 0:477258d09353 boosterpack
[svn r1] initial import
author | robert |
---|---|
date | Sun, 30 Aug 2009 02:19:26 -0400 |
parents | |
children |
rev | line source |
---|---|
robert@0 | 1 #!C:/strawberry/perl/bin/perl.exe |
robert@0 | 2 |
robert@0 | 3 # this is an example script of how you would use coderefs to define |
robert@0 | 4 # your CGI::Ajax functions, and the methods return multiple results to |
robert@0 | 5 # the page |
robert@0 | 6 # |
robert@0 | 7 # NB The CGI::Ajax object must come AFTER the coderefs are declared. |
robert@0 | 8 |
robert@0 | 9 use strict; |
robert@0 | 10 use CGI::Ajax; |
robert@0 | 11 use CGI; |
robert@0 | 12 |
robert@0 | 13 my $q = new CGI; |
robert@0 | 14 |
robert@0 | 15 my $multiply = sub { |
robert@0 | 16 my $a = shift; |
robert@0 | 17 my $b = shift; |
robert@0 | 18 return $a * $b; |
robert@0 | 19 }; |
robert@0 | 20 |
robert@0 | 21 my $divide = sub { |
robert@0 | 22 my $a = shift; |
robert@0 | 23 my $b = shift; |
robert@0 | 24 return $a / $b; |
robert@0 | 25 }; |
robert@0 | 26 my $G = 'asdf'; |
robert@0 | 27 my $Show_Form = sub { |
robert@0 | 28 my $html = ""; |
robert@0 | 29 $html .= qq! |
robert@0 | 30 <HTML> |
robert@0 | 31 <HEAD><title>CGI::Ajax Multiple Return Value Example</title> |
robert@0 | 32 <script> |
robert@0 | 33 my_call = function(){ |
robert@0 | 34 document.getElementById('out1').value = arguments[0]; |
robert@0 | 35 call_2(); |
robert@0 | 36 document.getElementById('out3').innerHTML = this.url; |
robert@0 | 37 } |
robert@0 | 38 call_2 =function(){ |
robert@0 | 39 multiply(['val1','val2'],['out2'],'POST'); |
robert@0 | 40 } |
robert@0 | 41 |
robert@0 | 42 </script> |
robert@0 | 43 </HEAD> |
robert@0 | 44 <BODY> |
robert@0 | 45 <form> |
robert@0 | 46 Enter Number: |
robert@0 | 47 <input type="text" id="val1" size="6" value=2 |
robert@0 | 48 onkeyup="divide(['val1','val2','args__$G'], [my_call], 'POST');"> |
robert@0 | 49 <input type='text' id='val2' size=6 value=34> |
robert@0 | 50 |
robert@0 | 51 <input type=text id="out1"> |
robert@0 | 52 <input type=text id="out2"><br/> |
robert@0 | 53 URL FROM "this" in callback:<div id="out3"> </div> |
robert@0 | 54 |
robert@0 | 55 |
robert@0 | 56 </form> |
robert@0 | 57 </BODY> |
robert@0 | 58 </HTML> |
robert@0 | 59 !; |
robert@0 | 60 |
robert@0 | 61 return $html; |
robert@0 | 62 }; |
robert@0 | 63 |
robert@0 | 64 |
robert@0 | 65 my $pjx = CGI::Ajax->new( 'multiply' => $multiply, 'divide' => $divide); |
robert@0 | 66 $pjx->JSDEBUG(1); |
robert@0 | 67 $pjx->DEBUG(1); |
robert@0 | 68 print $pjx->build_html($q,$Show_Form); # this outputs the html for the page |