1 perl comment #!/usr/bin/perl -w
3 perl comment # ajaxCheckbox.pl - a script to test Ajax functionality
6 perl code use CGI qw/:standard/;
7 perl code use CGI::Ajax;
10 perl comment # --- database authenication
11 perl code my $dbh = do 'db.inc';
13 perl code my $query = q{ SELECT project.project_id, project.name, project.phase, prio.prio,
14 perl code HEX((255 - prio.prio)) AS hex, begun, tags
15 perl code FROM project JOIN prio
16 perl code ON (project.project_id = prio.project_id)
17 perl code WHERE completed < 1
18 perl code ORDER BY prio.prio DESC LIMIT 3};
20 perl code my $sth = $dbh->prepare($query);
21 perl code $sth->execute();
22 perl code my $result = $dbh->selectall_arrayref($sth);
24 perl code my $cgi = new CGI;
25 perl code my $pjx = new CGI::Ajax( 'toStruck' => \&perl_func );
26 perl code print $pjx->build_html( $cgi, \&Show_HTML);
28 perl code sub Show_HTML {
30 perl code use CGI qw/:standard/;
32 perl code my $html = <<HEAD;
33 perl code <!DOCTYPE html
34 perl code PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
35 perl code "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
36 perl code <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
38 perl code <title>This is the lastest source version</title>
39 perl code <link rel="stylesheet" type="text/css" href="/css/carrot.css" />
40 perl code <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
41 perl code </head><body>
42 perl code <h2>Carrot Queue</h2><a href="/cgi-bin/source_carrot/index.cgi">Priority List</a><b> | </b>
43 perl code <a href="/cgi-bin/source_carrot/add.cgi">Add a listing</a><b> | </b><div class="content" /><h4>Project listing</h4>
46 perl code foreach my $row (@$result) {
47 perl code $html .= "<input type=\"checkbox\" name=name" . @$row[0] . " id=val" . @$row[0] . " value=\"ON\" onClick=\"toStruck( ['val@$row[0]'], ['div@$row[0]'] );\">";
48 perl code $html .= "<div id=\"div@$row[0]\" style=\"display: inline;\"><!-- This gets entirely replaced -->" . @$row[1] . "</span></div><br>";
51 perl comment # you can append stuff to the HTML this way
52 perl code $html .= "</body></html>";
54 perl code return $html;
57 perl code sub perl_func {
58 perl code my $input=shift;
60 perl comment # if onClick the change the style
61 perl code if ($input eq "ON") {
62 perl code $input="<span style=\"text-decoration: line-through; display: inline;\">";
64 perl code $input ="<span style=\"text-decoration: none; display: inline;\">";