I think I'm having a scope issue. Here's what is going on:

I have a .php file that I'll call "x.php" that is including a full HTML page, header and all. I have an external javascript file linked in this HTML (it's actually a PHP file that outputs my javascript). However, I have a function in this external javascript file that is using PHP to reference a variable from x.php. However, the variable is empty and it seems that I can't access the variable from x.php even though all of this code is in the same PHP file.

Can external Javascript sheets written with PHP not access PHP variable from the page it's link to? If not, is there a way to work around this?

Any help is appreciated. Thanks.

    Can you show us some examples? I'm not sure exactly what you're talking about... are you trying to access a PHP variable within Javascript code? If so, that would be the problem - the two languages are on opposite ends of the spectrum: JavaScript is a client-side language while PHP is a server-side language.

      Actually, I think I've found a work-around that fixes my problem.

      I used a combination of:
      $java_id= "../../scripts/gallery.php?id=".$xml->page[5]->page[0]->page[0]['id'];

      and

      <script language="javascript" type="text/javascript" src=<?php echo $java_id; ?>></script>

      to solve my problem :-)

        Write a Reply...