Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry How to return value from javascript to perl variable in cgi file

    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...
    [img]:cry:[/img]

    the way i m doing is,

    cgi file,

    Code:
    #!/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...........

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,928
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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.
    Last edited by Philip M; 07-28-2009 at 08:25 AM.

  • #3
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    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>























    Quote Originally Posted by Philip M View Post
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •