Re: passing values into javascript [message #179874 is a reply to message #179873] |
Sat, 15 December 2012 13:22 |
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
|
|
|