JavaScript in PHP or PHP in JavaScript
| From: | Robb Kerr | Date: | Fri, 23 Jul 2004 21:54:50 +0000 |
| Subject: | JavaScript in PHP or PHP in JavaScript | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-191699@lists.php.net to get a copy of this message | ||
Let me preface this by saying that I don't know JavaScript. I've got a page
that is built by a long complicated JavaScript that I was able to hack just
enough to function the way I wanted. There are some lines of code -- those
that define div positioning -- that need to be different depending upon
what it obtained from my database. I could build a simple PHP if/then
statement and embed the entire JavaScript with the lines changed. Or, I
could build a simple PHP if/then statement with only the lines of
JavaScript that need to be changed and embed it within the JavaScript.
which would be better?
JavaScript in PHP
<?php
if (conditional) {
?>
several lines of JavaScript
<?php
}
?>
PHP in JavaScript
<script language="JavaScript">
several lines of JavaScript
<?php
if (conditional) {
echo 'lines of JavaScript';
} else {
echo 'other lines of JavaScript';
}
?>
several lines of JavaScript
</script>
Thanx,
Robb
--
Robb Kerr
Digital IGUANA
Helping Digital Artists Achieve their Dreams
----------------------------------------------------
http://www.digitaliguana.com
http://www.cancerreallysucks.org