Re: Get PHP generated Javascript to work
| From: | Kevin Stone | Date: | Fri, 16 May 2003 18:06:35 +0000 |
| Subject: | Re: Get PHP generated Javascript to work | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-147949@lists.php.net to get a copy of this message | ||
----- Original Message -----
From: "Info@Best-IT" <info@best-it.biz>
To: "PHP general" <php-general@lists.php.net>
Sent: Friday, May 16, 2003 11:39 AM
Subject: [PHP] Get PHP generated Javascript to work
> I have a drop dow list with the following options:
>
> "<option name=\"title$i\" value=\"$id\" onChange=\"return
> reloadLoc();\">$element</option>\n";
>
> It is getting built in a while loop. I also have a file called loc.html
> that holds the java script function. So I read in that function with the
> following method:
>
> function SetScripts($filename)
> {
> $handle = fopen($filename, "r");
> $contents = fread($handle, filesize($filename));
> $this->scripts = $contents;
> fclose($handle);
> }
>
> $this->scripts then gets passed to a display() function. The HTML looks
> good in the source code of the page but does not execute. Here is my JS:
>
>
> <script language="JavaScript1.4" type="text/javascript">
> function reloadLoc()
> {
> window.location.href =
"http://cajunmikes.com/adminform.php?table=$id";
> window.location.reload();
> }
> </script>
>
> Any insights why it won't work?
The only potential problem I see looking at your code here is that variable
$id in the loc.html file won't be parsed when you execute the script. The
variable should be enclosed in php tags <?= $id?> and parsed by
include()'ing the file into your script rather than fopen()'ing it.
I don't know if that was the problem. But if not then explain exactly what
"wont' work" about the script.
HTH,
Kevin