Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Dec 2003
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    loading javascript from perl in javascript

    Okay, Here's what I can do:

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

    <script type="text/javascript">
    alert(myvar);
    </script>


    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
    </script>

    but that obviously doesn't work. Any ideas?

  • #2
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    <script type="text/javascript" src="http://www.myurl.net/myperl.pl"></script>
    
    <script type="text/javascript">
    window.onload = function () {
        alert(myvar);
    }
    </script>

  • #3
    New to the CF scene
    Join Date
    Dec 2003
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Dec 2003
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,045
    Thanks
    0
    Thanked 251 Times in 247 Posts
    You might get some idea from here

  • #7
    New to the CF scene
    Join Date
    Dec 2003
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cool! Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •