Re: help, please, understanding my problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2010-02-22 at 09:09 -0600, Stan wrote:

> I have a PHP page that has
>  require_once("genMyOverlay.js.php");
>  .
>  .
>  .
>  echo "<body>";
>  echo "<script language=\"JavaScript\">doit(\"mydiv\");</script><br>";
>  echo "</body>";
> 
> genMyOverlay.js.php contains: createDiv() (see below) that creates a <DIV
> ID="mydiv"> and sets it up to overlay a portion of the wbe page and
> doit()starts it off.
> 
> invoke the web page once and it works like it should.  invoke the web page a
> second time (and thereafter until a new session) and it gets error:
>  "doit is not defined"
> 
> view the source (at the client browser) and it is identical both (all) times
> 
> can anyone please help me understand what is happening?
> 
> genMyOverlay.js.php contains
>  <script language="PHP">
>   echo "<script language=\"JavaScript\">";
>   echo "function createDiv()";
>   echo " {";
>    .
>    .
>    .
>   echo " }";
>   echo "function doit(ElementID)";
>   echo " {";
>   echo " creatDIV()";
>    .
>    .
>    .
>   echo " }";
>   echo "</script>";
>  </script>
> 
> 
> 


Going on just that sample, there's no issue. As it works the first time,
there isn't a problem with it not getting included. Have you tried it on
other browsers to see what happens there? Also, Firefox has a brilliant
addon called Firebug, which can show you the contents of included .js
files on your page, which will show up any problems you may have.

Aside from these points, have you a good reason for including a PHP file
that just outputs javascript? Why not just include the .js file as part
of the header?

Also, your script tags need a type attribute:

<script language="javascript" type="text/javascript">

And lastly, instead of lots and lots of echo statements in your page,
have you looked at heredoc and nowdoc syntax in PHP?

echo <<<EOC
lots and lots of output lines go here.
EOC;

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux