/    Sign up×
Community /Pin to ProfileBookmark

Using javascript variables

Hi.
I’m using Perl and JavaScript into a script.
I have this JavaScript function inside a Perl script:

print “function confirm(data)n”;
print “{n”;
print ” var erase=confirm(“Do you really want to erase ALL contents of this session: “+data+”?”);n”;
print ” if (erase)n”;
print ” {n”;
$job=data; <—- I hope it were that simple!!!!
print “}n”;
print “}n”;

I need to assign JavaScript variable data’s value to a Perl variable called $job in order to use it later.

Any ideas?

I’ll appreciate any help given.

Thanks in advance

Freddy A. Rojas P.

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@ExuroSep 13.2004 — What you're going to need to do is pass the variable to the Perl script via the query string. You would then retrieve the data from the query string with your Perl script, and procede to remove the data or whatever you're doing.
Copy linkTweet thisAlerts:
@CharlesSep 14.2004 — We need a little more information to be really helpful, but...

  • * You need to read the CGI.pm documentation.


  • * You need to know about Perl's "<<" quotes.
  • Copy linkTweet thisAlerts:
    @rfreddyauthorSep 14.2004 — Hi.

    Thanks for the help.

    I know how to pass variables trought query string, but I need the function runs before sending form's variables to another cgi.

    I've thinking about use environment variables to solve this problem, but I don't know how to set it using JavaScript.

    Bye.

    Freddy.
    Copy linkTweet thisAlerts:
    @CharlesSep 14.2004 — [font=monospace]use CGI qw (script);

    $script = <<EndOfJavaScript;

    <!--

    if (confirm('Do you really want to erase ALL contents of this session: ' + data + '?')) {

    var img = new Image();

    img.onerror = function () {alert ('Unable to contact $0')};

    img.src = '$0?data=' + escape (data);

    }

    }

    // -->

    EndOfJavaScript

    print script ({-type => 'text/javascript'}, $script);[/font]
    Copy linkTweet thisAlerts:
    @rfreddyauthorSep 14.2004 — Hi.

    I'm a little bit confused with the code. Why do you call an image?

    I want to use the data's value to do this thing in Perl:

    $job={value of data};

    system ("rm -r /home/$user/$job");

    I'm looking forward to do a perl interactive delete function using the advantage of JavaScript's confirm function in the same script.

    Thanks you very much for your help and forgive my annoyance.

    Freddy.
    Copy linkTweet thisAlerts:
    @CharlesSep 14.2004 — JavaScript cannot communicate with the external world, but with one exception. It can be used to cache an image. The trick is to make JavaScript think that your Perl script is an image, and there's no reason it shouldn't be. Just pass your data along with the URL, use the CGI module to parse it and then return an empty image to avoid a call to the image's "onerror" handler.
    Copy linkTweet thisAlerts:
    @rfreddyauthorSep 20.2004 — Hi.

    I figured out how to pass data between JS and Perl!, I wrote data's content in a cookie with JS and later I read this cookie with perl using CGI.pm module. Works like a charm.

    Thanks to everyone for your help.

    Bye.

    Freddy A. Rojas P.
    ×

    Success!

    Help @rfreddy spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.19,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...