Forum Moderators: coopster

Message Too Old, No Replies

javascript in php question

         

electricocean

3:48 am on Jun 5, 2005 (gmt 0)

10+ Year Member



Hi I have never done javascript in php before.

Here's my question:

All the lines in javascript normally end with a ';' but the php echo always ends in a ';' too.

the javascript ';' means the end of the line and so does the php.

do I do both ';'? or just php's... I am so confused!

thanks,
electricocean

ekram

4:31 am on Jun 5, 2005 (gmt 0)

10+ Year Member



<?php

echo "<script language=\"JavaScript\">alert(\"My name is ekram\");</script>";

?>

electricocean

4:36 am on Jun 5, 2005 (gmt 0)

10+ Year Member



well my scipt is [retty long:

echo "<script language=\"javascript\">";
echo "var w = window.open('',$title,'width=500,height=500,scrollbars=yes,resizable=yes');";
echo "var d = w.document;"
echo "d.write('<html><head>$title</head><body>DKicks Jokes / Jokes / $genre / $title<br>
<p align=\"center\"><table><tr><td><font size=\"30\">$title</font></td><td>Current Rating: $rating <input type=\"button\" value=\"Rate This Joke\" onclick=\"return rateJoke('$jtitle');\">
</td></tr></table></p><p align=\"center\">$joke</p><br><p align=\"right\"><a href=\"javascript:window.close();\"><<Back</a></body></html>');";
echo "d.close();"
echo "w.focus();"
echo "</script>";

saoi_jp

6:57 am on Jun 5, 2005 (gmt 0)

10+ Year Member



You can also just exit php and type the javascript in plain.

<?
your php code is here
?>
put your javascript here
<?
continue php here
?>

mcibor

12:20 pm on Jun 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You print both ";" for javascript and php. or as Saoi said exit php and write you java plain. Moreover it's better if you don't write echo just for one line (you won't regain formatting), but echo the whole text, eg:

echo "<script type=\"text/javascript\">
<!--
var a = 2;
var b = $bla;
var c = a + b;
document.write('Sum: ' + c);
//-->
</script>";

Then it's quite clear what's javascrip and what's php.

Best regards
Michal Cibor