Re: JavaScript in PHP or PHP in JavaScript
| From: | Torsten Roehr | Date: | Sat, 24 Jul 2004 09:10:39 +0000 |
| Subject: | Re: JavaScript in PHP or PHP in JavaScript | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-191730@lists.php.net to get a copy of this message | ||
"Robb Kerr" <rkerr.news@digitaliguana.com> wrote in message
news:o8upk9kxrdys$.12qymbg4amjxn.dlg@40tude.net...
> 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
Hi Rob,
maybe you can use the ternary operator syntax for the affected lines:
echo (conditional) ? 'lines of JavaScript'
: 'other lines of JavaScript';
Regards, Torsten Roehr