JavaScript with Php.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

JavaScript with Php.

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all


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


User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post 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.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

Short tags very bad, my son. Sorry you will be.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

Short tags very bad, my son. Sorry you will be.
I don't understand?
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post 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
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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:
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

That sucks. :lol:
Ward
Forum Commoner
Posts: 74
Joined: Thu Jul 13, 2006 10:01 am

Post by Ward »

This is a little quicker than having to type 'echo'

Code: Select all

var thisValue = '<?=$thisValue?>';
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

<?= only works with short tags enabled. will break on PHP 6 if you care :-D
Ward
Forum Commoner
Posts: 74
Joined: Thu Jul 13, 2006 10:01 am

Post by Ward »

what about <?php=$myVar?>?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

that's still short tags
Post Reply