FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » passing values into javascript
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: passing values into javascript [message #179874 is a reply to message #179873] Sat, 15 December 2012 13:22 Go to previous messageGo to previous message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma:
Senior Member
In article <kahssi$3u7$1(at)dont-email(dot)me>,
Denis McMahon <denismfmcmahon(at)gmail(dot)com> wrote:

> On Fri, 14 Dec 2012 22:09:12 -0500, richard wrote:
>
>> As PHP creates the html page, it would be, or should be, rather simple
>> to produce a line of code for that line of JS.
>> Such as Echo "<script>code</script>"
>
> Yep.
>
> Now all you have to do is work out how to get the values you want where
> you have "code".
>
> Simples. Google "javascript variable assignment"
>
> It's probably something like:
>
> echo "<script type='text/javascript'>var jsvarname = {$phpvarname};</
> script>\n";

Personally I try to keep the PHP part as small as possible, so inside
the top section of my JS where I'm initialising some variables, it's
likely to be something like:


var myjsVar = <?php echo $myphpvar; ?> ;


As the man says: simples!

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: HP syntax error, unexpected T_variable
Next Topic: Using echo to run separate PHP script from HTML
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 20:23:55 GMT 2024

Total time taken to generate the page: 0.04167 seconds