Link to home
Start Free TrialLog in
Avatar of JaimeJegonia
JaimeJegoniaFlag for United States of America

asked on

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
Avatar of mjcoyne
mjcoyne

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;
ASKER CERTIFIED SOLUTION
Avatar of jhurst
jhurst

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
seems to me that the question is pretty clear and unambiguous.  What are you suspecting Tintin?
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JaimeJegonia

ASKER

thanks to everyone who answered.

i'll just try to find other method/ways than trying to communicate javascript with perl.
You still haven't told us what problem you're trying to solve.
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?
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. :)