• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 732
  • Last Modified:

access a javascript variable in perl

is there anyway that i can access a javascript variable in perl??

say, i have declared a variable inside the script

<------------------------------------------------->

#!/usr/bin/perl
#enterpoints.cgi

use DBI;
use CGI qw(:standard);
use CGI qw(:all);

print <<END;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<script type="text/javascript">
var test = "hello world"; <!-- this is the variable i'm referring at-->
</script>

END

#perl code here
#is there any way that i could print that variable test above here????
<------------------------------->

what i mean is that, can i assign its(var test) value to another variable declared in perl???
please help.... thanks
0
JaimeJegonia
Asked:
JaimeJegonia
  • 3
  • 3
  • 2
  • +1
3 Solutions
 
mjcoyneCommented:
You could have Javascript call your Perl script, passing the variable name to it:

var test = "hello world";
var URL = eval('http://www.yourserver.com/cgi-bin/yourPerlscript.pl?test=' + test);
document.location.href = URL;
0
 
jhurstCommented:
The basic answer to your question is no, altough as has been pointed out you can sort of do it.  Basically the perl script is executed when it is generating the Javascript.  The javascript itself will not be executed until later, therefore, there is no direct way in which the thing that happens first, being the perl, can access the thing that happens later, being the Javascript.
0
 
TintinCommented:
Let's go back a few steps and get you to describe the problem you are trying to solve, rather than trying to solve the problem how you think it needs to be done.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
jhurstCommented:
seems to me that the question is pretty clear and unambiguous.  What are you suspecting Tintin?
0
 
TintinCommented:
The question is very clear, but the reasoning is possibly not.  This may (or may not be) a classic case of the XYZ problem, where the person has problem X and has decided that solution Y is the way to achieve it rather than solution Z.  But without knowing X, we can only answer Y and not Z.
0
 
mjcoyneCommented:
An excellent point, Tintin -- there may be other, simpler ways of achieving the same result without relying on JavaScript-Perl cross-communication.
0
 
JaimeJegoniaAuthor Commented:
thanks to everyone who answered.

i'll just try to find other method/ways than trying to communicate javascript with perl.
0
 
TintinCommented:
You still haven't told us what problem you're trying to solve.
0
 
jhurstCommented:
I think that you have your answer then.  We have told you what is possible and what is not.  Why is that not an answer?
0
 
JaimeJegoniaAuthor Commented:
well, basically the problem is that, i want to make my page dynamic so i used an input of type button so it doesn't refresh the page. but with this i can't fetch my variables in javascript in my perl code. it's hard so i thought that it would just be easy if i use the input of type "submit" and just do the addtitional fields after the page has loaded. and jhurst suggested that it can't be done. so i'm tryng to figure out some way.

And i think tintin, made a point. im so focused with javascript-perl connection(literally). i haven't realize that there other ways to solve it. I've tried to use ajax and it worked! thanks a lot guys. :)
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now