tiger1974

Project 3 - Displaying a specific ENV Key/Value via JS/AJAX

May 18th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.48 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use CGI;
  5. my $q = CGI->new();
  6. my $key = $q->param('key');
  7. my $value = $ENV{$key};
  8. print "content-type: text/html \n\n";
  9. my $keys = %ENV;
  10. print "<html><head><script type=\"text/javascript\">
  11. function getkey(key) {
  12.        var txtHint = document.getElementById('txtHint');
  13.                if (key=='') {
  14.                        {
  15.                                txtHint.innerHTML='';
  16.                                return;
  17.                        }
  18.                if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
  19.                else { xmlhttp=new ActiveXObject('Microsoft.XMLHTTP') }
  20.                xmlhttp.onreadystatechange=function() {
  21.                        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
  22.                                txtHint.innerHTML=xmlhttp.responseText;
  23.                        }
  24.                }
  25.                xmlhttp.open('GET','proj3.pl?key='+key,true);
  26.                xmlhttp.sent();
  27.        }      
  28. </script>";
  29. print "</head><body>";
  30. print "<div align=\"center\">Please select an ENV key<br>";
  31. print "<form><select name=\"key\" onchange=\"getkey(this.value)\">\n";
  32. foreach my $key (keys %ENV) {
  33.         print "<option value=\"$key\">$key</option>", "\n";
  34.         }
  35. print "</select><input type=\"submit\" value=\"Get the Key Value\">";
  36. print "</form></div>";
  37. print "<div align =\"center\" id=\"txtHint\">ENV Key => $key <br> Key Value => $value</div>";
  38. print "</body></html>";
Advertisement
Add Comment
Please, Sign In to add comment