View Full Version : loading javascript from perl in javascript

01-09-2004, 06:57 PM
Okay, Here's what I can do:

<script type="text/javascript" src="http://www.myurl.net/myperl.pl"></script>

<script type="text/javascript">

The problem is what I need to be able to do is manipulate some variables in javascript and then call the perl script using those variables and then use the variables the perl script brings back.

Something like the following:
<script type="text/javascript">
var myvar = 3;
<script type="text/javascript" src="http://www.myurl.net/myperl.pl?perlvar="+myvar></script>
alert(myvar2); //myvar2 returned by myperl.pl

but that obviously doesn't work. Any ideas?

01-09-2004, 07:28 PM
You have to wait until the document's loaded to access any variables created by external scripts. Why the whole document? Because you can't be sure the script has loaded until then. Check this, it should work:

<script type="text/javascript" src="http://www.myurl.net/myperl.pl"></script>

<script type="text/javascript">
window.onload = function () {

01-09-2004, 07:34 PM
That would work, except that a function on that page would have to update a variable that is sent to the perl script. Trying to translate this from a flash action script where they were doing

function myfunction() {
mess with a bunch of variables
load variables from perl script using the variables above
mess with variables from perl scripts

I'd hate to have to do

run function
post to a page
run function using new values

01-09-2004, 07:59 PM
assuming the vars from the perl is returned in javascript u can do the following.

1. load the page.
2. tamper with variable.
3. load the perl file in an onload function into a script tag.
4. make the last line of the perl file call a function to tamper with the variables.

01-12-2004, 08:43 PM
Thanks for the responses. I talked to a member on my team and he says he has a way to do it. I don't know exactly what he's doing, otherwise I would post it here. Thanks again for the help.

01-13-2004, 04:55 AM
You might get some idea from here (http://www.codingforums.com/showthread.php?s=&threadid=16205)

01-13-2004, 07:51 AM
Cool! Thanks.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum