robert@2
|
1 #!C:/strawberry/perl/bin/perl.exe
|
robert@2
|
2 use strict;
|
robert@2
|
3 use CGI::Ajax 0.57;
|
robert@2
|
4 use CGI;
|
robert@2
|
5
|
robert@2
|
6 my $q = new CGI; # need a new CGI object
|
robert@2
|
7
|
robert@2
|
8 # compose our list of functions to export to js
|
robert@2
|
9 my %hash = ( 'myFunc' => \&perl_func,);
|
robert@2
|
10
|
robert@2
|
11 my $pjx = CGI::Ajax->new( %hash ); # this is our CGI::Ajax object
|
robert@2
|
12
|
robert@2
|
13 $pjx->DEBUG(1); # turn on debugging
|
robert@2
|
14 $pjx->JSDEBUG(1); # turn on javascript debugging, which will place a
|
robert@2
|
15 # new div element at the bottom of our page showing
|
robert@2
|
16 # the asynchrously requested URL
|
robert@2
|
17
|
robert@2
|
18 print $pjx->build_html( $q, \&Show_HTML ); # this builds our html
|
robert@2
|
19 # page, inserting js
|
robert@2
|
20
|
robert@2
|
21 # This subroutine is responsible for outputting the HTML of the web
|
robert@2
|
22 # page.
|
robert@2
|
23 sub Show_HTML {
|
robert@2
|
24 my $html = <<EOT;
|
robert@2
|
25 <HTML>
|
robert@2
|
26 <HEAD><title>Radio Example</title>
|
robert@2
|
27 </HEAD>
|
robert@2
|
28 <BODY>
|
robert@2
|
29 <form>
|
robert@2
|
30 <DIV id="radiobuttons" onclick="myFunc( ['radio1'], ['result'] );">
|
robert@2
|
31 <input TYPE="radio" ID="radio1" NAME="radio1" VALUE="red">red
|
robert@2
|
32 <input TYPE="radio" ID="radio1" NAME="radio1" VALUE="blue">blue
|
robert@2
|
33 <input TYPE="radio" ID="radio1" NAME="radio1" VALUE="yellow">yellow
|
robert@2
|
34 <input TYPE="radio" ID="radio1" NAME="radio1" VALUE="green">green
|
robert@2
|
35 </DIV>
|
robert@2
|
36 <div id='result'> </div>
|
robert@2
|
37 </form>
|
robert@2
|
38 </BODY>
|
robert@2
|
39 </HTML>
|
robert@2
|
40 EOT
|
robert@2
|
41
|
robert@2
|
42 return($html);
|
robert@2
|
43 }
|
robert@2
|
44
|
robert@2
|
45 # this is the exported function
|
robert@2
|
46 sub perl_func {
|
robert@2
|
47 $a = shift;
|
robert@2
|
48 return $a . " was selected";
|
robert@2
|
49 }
|