Page 1 of 1

[SOLVED] PHP and JAVA Script

Posted: Mon Nov 01, 2004 4:32 pm
by tstimple
Before I get into all the details...

Is it possible to dynamically build JAVA Script on a web page using PHP?

--Tim

Posted: Mon Nov 01, 2004 4:33 pm
by Weirdan
Certainly.

Posted: Tue Nov 02, 2004 4:18 am
by CoderGoblin
Building PHP is like assuming PHP is an "HTML editor", it just adds text to a "file", even if the "file" is really just memory. All you need to do is output the script as though it was HTML..

Very Simple Example:

Code: Select all

<?php
echo('<html>
<head>
<title>Pointless test</title>
</head>
<body>
<script language="javascript">
function writeText(mytext)
{ document.write(mytext); }
</script>
<script language="javascript">alert("Hello World");</script>
  <p> Well This is written by PHP </p>
  <script language="javascript">
  writeText("This is HTML written via javascript function");
<noscript>This dummy needs Javascript</noscript> 
</body>
</html>');
?>