#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Italy
    Posts
    16
    Rep Power
    0

    Unhappy PHP and Javascript


    Hi all,
    I'm in front of a strange problem that I'll try to explain.

    I'm using PhpNuke and I wish to do the following thing. I wish to include an external javascript and it's quite simple to do it in Php:
    PHP Code:
    echo "<script language=\"Javascript\" src=\"external.js\"></script>"
    The problem is this: I wish to set a variable for the external JS which has to be parsed first from Php.

    Just to clear my intent:

    Code:
    // this is my external.js
    
    function Ripristina() {
    document.form.monitor.value=""+varText;
    }
    How can I define varText in php?
    I am asking that as I try (with no results) this way:
    PHP Code:
    echo "<script language=\"Javascript\" src=\"external.js\">\n";
    $varText translate("Bla bla");
    echo 
    "varText = \"$varText\"\n";
    echo 
    "</script>"
    I hope there is someway else to do this trick and I hope someone more expert than me knows how.

    Regards.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jul 2001
    Location
    Oslo
    Posts
    1,516
    Rep Power
    15
    F*CK. Sorry, but the software running this forum once again crashed when parsing my post, and naturally, going back doesn't work on this bloody site, so my post was lost. Goddamn.

    Anyway. What you need to do is this (pseudo code):
    1. Print out a script type="javascript" tag in which you set your javascript variable.
    2. Print out another script tag like the one you're using now, with the source.

    Do it in that order, you need to make sure that the javascript variable becomes available in the referenced js file.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Italy
    Posts
    16
    Rep Power
    0

    Wink


    Thanks.

    It solved my problem.

    Why didn't I think about it before?


    Thanks for your suggestion.

    Bye.

IMN logo majestic logo threadwatch logo seochat tools logo