...

View Full Version : How to return value from javascript to perl variable in cgi file



nehasanap
07-28-2009, 08:53 AM
Hello friends,
I want to check whether the flash is installed or not on client so i have a javascript function which does this , now i want the resultant variable from this function to return to perl variable in cgi file. i dont want to use form submit because i dont need it. i simply have to take decision for further coding depending on this variable returned from javascript.
How to do this...??
can anyone help me please...
:cry:

the way i m doing is,

cgi file,



#!/usr/bin/perl
require './draw_pie.pl';
%lv=("lv1"=>'20',"lv2"=>'10',"lv3"=>'30',"lv4"=>'25',"lv5"=>'10',"lv5"=>'5');
$flag=&check_flash_exist();
use CGI qw/:standard/;
my $cgi = new CGI;
if($flag=='true')
{ &draw_pie(\%lv,"vgname",100,1);
}
else {
&draw_pie(\%lv,"vgname",100,0);
}

and the corresponding draw_pie.pl is,

sub check_flash_exist()
{
print "Content-Type: text/html\n\n";
print "<html><head>";
print "<script src=\"client_side_detection\\AC_OETags.js\" language=\"javascript\"></script>
</head>";
print "<body>";
print "<script type=\"javascript\">
var requiredMajorVersion = 8
var requiredMinorVersion = 0
var requiredRevision = 0
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion,requiredMinorVersion,requiredRevision);
return hasReqestedVersion ;
</script>
</body></html>";
}
sub draw_pie() {}

please help me...........

Philip M
07-28-2009, 09:15 AM
Normally you can only pass a Javascript variable to a Perl script by using a form and submit action. Include a form on your page with hidden fields. When an event occurs, fill the hidden fields with your JS variables and submit the form to your cgi program.

Another possibility is a cookie: JS sets a cookie on the user's machine once it has determined the variables. Perl reads that cookie to get the variables.

Yet another possbility is AJAX.



All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

nehasanap
07-28-2009, 12:03 PM
hi friend,
I tried with ur suggestion for the cookie but now what happens is after refreshing the url i.e .cgi file i am getting the modified the value of flash detection.
When i disable the flash then i requires to refresh twich to get the new value..
i m very confused why this is happening...can u guide me please..

Code anippet is,
<CODE>
CGI file is---
#!/usr/bin/perl
require './draw_pie.pl';
%lv=("lv1"=>'20',"lv2"=>'10',"lv3"=>'30',"lv4"=>'25',"lv5"=>'10',"lv5"=>'5');
$flag=&check_flash_exist();
use CGI qw/:standard/;
my $cgi = new CGI;
print $cgi->header( -expires => 'now' -"Cache-Control"=>"no-store, no-cache, must-revalidate");
$name = cookie(-name=>"ppp");
print "-------ppp==$name";

and draw.pl file---

sub check_flash_exist()
{
print "Content-Type: text/html\n\n";
print "<html><head>";
print "<script src=\"client_side_detection\\AC_OETags.js\" language=\"javascript\"></script>
</head>";
print "<body>";
print "<script type=\"text/javascript\">
var requiredMajorVersion = 8
var requiredMinorVersion = 0
var requiredRevision = 0
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion,requiredMinorVersion,requiredRevision);
var d=new Date();
if(hasReqestedVersion){
document.cookie =\"ppp=1\";
}
else {
document.cookie =\"ppp=0 \";
}
</script>
</body></html>";
}
</CODE>
























Normally you can only pass a Javascript variable to a Perl script by using a form and submit action. Include a form on your page with hidden fields. When an event occurs, fill the hidden fields with your JS variables and submit the form to your cgi program.

Another possibility is a cookie: JS sets a cookie on the user's machine once it has determined the variables. Perl reads that cookie to get the variables.

Yet another possbility is AJAX.



All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum