Tool
Tool

Reputation: 12488

JS/PHP/HTML problem with onload

index.php

<html>

<head>
<script language="JavaScript" src="lol.js.php"></script>
</head>


<?php
    //grab product id's who need to be showed
    $pids = '1,2,3';
?>

<body onload="update_timers();">

lol.js.php

<script type="text/javascript">

function update_timers()
{
    alert('hi');
}
</script>

I'm not sure what I'm missing, but this isn't poping up the alert window. Why is that?

Upvotes: 1

Views: 312

Answers (1)

Pekka
Pekka

Reputation: 449395

Remove

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

from the JS file.

The JavaScript error console in your browser should show these tags as syntax errors.

Also, as @Jared points out, you should send a content type header:

<?php header("Content-type: text/javascript"); ?>

Upvotes: 6

Related Questions