Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

passing PHP varibales to Javascript...

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

passing PHP varibales to Javascript...

Postby eyewoo » Sat Jun 14, 2003 1:33 pm

... is there a way?

I thought this would work:
Code: Select all

<script langauge="javascript">
myJVab = <?=$MyPHPVab?>;
document.write(myJVab + ' has been passed to Javascript from PHP<hr>');
</script>



...but it doesn't... Apparently the <?= ?> do not have effect within the <script></script> tags... :cry:
eyewoo
New php-forum User
New php-forum User
 
Posts: 71
Joined: Sun Mar 09, 2003 10:29 am
Location: Pennsylvania, USA

ah-ha!!!!!

Postby eyewoo » Sat Jun 14, 2003 1:50 pm

Got it!

This on the other hand does work...

Code: Select all
<?
$myPHPVab='OneTwoThreeFour';
echo '
<script langauge="javascript">;
   var myJVab = "'.$myPHPVab.'";
   document.write(myJVab + " has been passed to Javascript from PHP<hr>");
</script>
';
?>


The <script></script> tags have to also be encased within the PHP tags... :D
eyewoo
New php-forum User
New php-forum User
 
Posts: 71
Joined: Sun Mar 09, 2003 10:29 am
Location: Pennsylvania, USA

Postby bonkers » Sat Jun 14, 2003 10:12 pm

Forgive me if I'm wrong cuz I'm a n00b at PHP but I thought that since the file is parsed for <??> tags that any other tags don't matter when it's in your HTML. So <?=$variable?> should work. Try <? echo $variable; ?>...might work ya neva know.
bonkers
New php-forum User
New php-forum User
 
Posts: 46
Joined: Wed Mar 12, 2003 7:17 pm

Postby eyewoo » Sun Jun 15, 2003 6:07 am

Nope... from my experiments, the HTML <script></script> tag has to be part of what is encased in the PHP <? ?> tags, i.e. the <script></script> tags have to be echo'd before the PHP variables can be inserted. At least that is the way it works using the Apache mod PHP. Perhaps it's different with the regular PHP... I've noticed other difference in the two versions of PHP.
eyewoo
New php-forum User
New php-forum User
 
Posts: 71
Joined: Sun Mar 09, 2003 10:29 am
Location: Pennsylvania, USA

Postby WiZARD » Sun Jun 15, 2003 11:37 pm

he-he-he :D :lol: :D
not straight, so a roundabout way
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 5 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.