Page 1 of 1

JavaScript with Php.

Posted: Tue Jul 18, 2006 3:17 am
by JellyFish
Hey.

I was wondering if it's prossible to give a JS variable the value of a php variable(which I'm sure there is a way), and such related?

Basicly I devote this topic to using JavaScript and PHP. So good things.

Posted: Tue Jul 18, 2006 3:23 am
by Benjamin

Code: Select all


var thisValue = '<?php echo $thisValue; ?>';



Posted: Tue Jul 18, 2006 3:29 am
by JellyFish
cool that simple eh. Yeah I got a little discouraged when I tried.

Code: Select all

var MyVar = </script><? $myvar ?><script>;
and

Code: Select all

var MyVar = <? $myvar ?>;
but yeah I get it now.

And that ain't all. As I said I devote this topic to all things javascript and php, when used together that is.

Posted: Tue Jul 18, 2006 3:30 am
by daedalus__
Short tags very bad, my son. Sorry you will be.

Posted: Tue Jul 18, 2006 3:38 am
by JellyFish
Short tags very bad, my son. Sorry you will be.
I don't understand?

Posted: Tue Jul 18, 2006 3:40 am
by daedalus__

Code: Select all

<? $myvar ?>;
no no no no no

no short tags.

just my opinion though.

plenty have threads have discussed it, i wont go into it in this one.

just a suggestion

Posted: Tue Jul 18, 2006 3:44 am
by JellyFish
Oh. Well I've had no troubles with "short tags". Is it browser support? I mean it saves three punches on the keyboard. :D

But if you don't want to get into it I understand. lol.

Posted: Tue Jul 18, 2006 3:49 am
by Benjamin
PHP 6 won't support them. You will also run into PHP installations which are not configured to support them. It's considered good practice not to use them, and you won't have to worry about your scripts breaking in the future. :wink:

Posted: Tue Jul 18, 2006 3:53 am
by JellyFish
That sucks. :lol:

Posted: Tue Jul 18, 2006 9:56 am
by Ward
This is a little quicker than having to type 'echo'

Code: Select all

var thisValue = '<?=$thisValue?>';

Posted: Tue Jul 18, 2006 11:11 am
by JayBird
Ward wrote:This is a little quicker than having to type 'echo'

Code: Select all

var thisValue = '<?=$thisValue?>';
Also generally considered bad practice

Posted: Tue Jul 18, 2006 11:23 am
by Charles256
<?= only works with short tags enabled. will break on PHP 6 if you care :-D

Posted: Tue Jul 18, 2006 9:37 pm
by Ward
what about <?php=$myVar?>?

Posted: Tue Jul 18, 2006 9:41 pm
by Luke
that's still short tags