Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Pass JavaScript variable to Perl subroutine and vice versa

Posted on 1998-12-03
3
Medium Priority
?
1,301 Views
Last Modified: 2009-10-22
Hi!
Is there a way to pass a JavaScript variable to a perl function? I need this variable to query the database and return the data to the JavaScript function.

This is a section of the code. I hope you can understand it!
ProductKey, FromRelease and ToRelease are selected variables from a form.

print "\n   if (ProductKey !=  form.key_name.options[0].selected) {";

print "\n     if (FromRelease != ToRelease) {";
print "\n       if (FromRelease < ToRelease) {";
               ?   $FromRelease = FromRelease;
               ?   $ToRelease = ToRelease;
               ?   $steps = &det_upg_steps($FromRelease,$ToRelease);
print "\n var step = \"$steps\";"; ?is this correct?
print "\n         display(FromRelease,ToRelease,step);";
 :
 :      

sub det_upg_steps {
  local($from_rel,$to_rel) = @_;
  local($steps);

  @res = &sql(q/SELECT DISTINCT STEP
                INTO :$steps
                FROM AD2000_UPG_STEPS
                WHERE AD2000_UPG_STEPS.FROM_REL = '$from_rel'
                AND AD2000_UPG_STEPS.TO_REL = '$to_rel'/);
  &sqlerr;

  return($steps);
}
 }";

0
Comment
Question by:bcoballe
3 Comments
 
LVL 4

Expert Comment

by:martinag
ID: 1275000
In order to communicate JavaScript => Perl you must run the perl script and pass the parameters to it. Here's one way of doing it, I guess there are a thousands of others.
script.pl?runFunction=det_upg_steps&var1=XXX&var2=XXX (a few lines of JavaScript to build the URL)

Then let your script check for runFunction, collect all variables passed as var1, var2, var3 etc and do eval on it. (a few lines of Perl)

Of course, if it's possible put det_upg_steps in its own file. Much easier...

Now, in order to get the result, there's a few solutions. About the ones that I come to think of this one seems to be the best:
Use a hidden frame. Print the output with JavaScript code so that it sets variables that will hold the result. Then the other (visible) frame reads the variables and use them. (a few lines of Perl and a few lines of JavaScript)

I don't think that should be so hard, but let me know if you need code in JavaScript or Perl.

Martin
0
 
LVL 1

Accepted Solution

by:
someu earned 200 total points
ID: 1275001
If you want to get the vars when he has clicked a form button, use:

<form method=get>
<input type=hidden value="" name="FormRelease"><!-- in name, is the name of the var you want to get-->
<input type=hidden value="" name="ToRelease">
<input type=submit value="submit form">
</form>

on cick the button the page will reload, but the values of the vars are in the search.
in the PERL code you must take the search vars with a famous PERL function.
If the search=="" then do not do anything.
:-D
0
 

Expert Comment

by:sumani100298
ID: 1275002
well, the way i do it is like this.

assuming you are having a FORM displayed and a BUTTON there to submit it
to the cgi program:

<script language="JavaScript">
<!-- hide from old browsers...
function TransferNSubmit(){
.
whatever calculations you want to do with the values in the hidden fields,
etc. you can do it here.
after all that..
...
document.mainform.submit();
}
//-->
</script>
<body>
<form name="mainform" action="yourPerlFileName.pl">


 all the values u display and get input from the user.....
<INPUT type="hidden" name="fromrelease" value="xxxxx">
<INPUT type="hidden" name="torelease" value="xxxxx">
<INPUT type="hidden" name="othervalue" value="xxxxx">
<INPUT type="button" name="SUBMIT" value="CLICK ME" onClick="TransferNSubmit();">
</form>

</body>


and in the perl file at the back end,
you can query for the values "fromrelease, torelease...." etc.
and if you do processing with fromrelease...etc at the perl side,
u can send back the values with the form, in the hidden field values..
$fromrelease = "something";
..
<input type="hidden" name="fromrelease" value="$fromrelease">
. something like this...

hth

mani
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question