From: "Stan" on
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>


From: Ashley Sheridan on
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


From: tedd on
At 3:15 PM +0000 2/22/10, Ashley Sheridan wrote:
>Also, your script tags need a type attribute:
>
><script language="javascript" type="text/javascript">
>

Actually, you only need this:

<script type="text/javascript">

The language attribute will throw an error in validation.

Cheers,

tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
From: Ashley Sheridan on
On Mon, 2010-02-22 at 12:33 -0500, tedd wrote:

> At 3:15 PM +0000 2/22/10, Ashley Sheridan wrote:
> >Also, your script tags need a type attribute:
> >
> ><script language="javascript" type="text/javascript">
> >
>
> Actually, you only need this:
>
> <script type="text/javascript">
>
> The language attribute will throw an error in validation.
>
> Cheers,
>
> tedd
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com
>


Never thrown an error for me! I guess it depends on what doctype you
use?

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


From: tedd on
At 5:32 PM +0000 2/22/10, Ashley Sheridan wrote:
>On Mon, 2010-02-22 at 12:33 -0500, tedd wrote:
>
>>
>>At 3:15 PM +0000 2/22/10, Ashley Sheridan wrote:
>>>Also, your script tags need a type attribute:
>>>
>> ><script language="javascript" type="text/javascript">
>>>
>>
>>Actually, you only need this:
>>
>><script type="text/javascript">
>>
>>The language attribute will throw an error in validation.
>>
>>Cheers,
>>
>>tedd
>>
>
>Never thrown an error for me! I guess it depends on what doctype you use?

I was trying to be discreet.

The "language" attribute has been depreciated. If you use a
"transitional" DOCTYPE, then it won't throw an error -- but the
"language" attribute is outdated and some consider it poor coding
practice to use depreciated attributes.

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
 |  Next  |  Last
Pages: 1 2
Prev: Fun with Streams
Next: $_POST vs $_REQUEST