Categories > TinyButStrong general >

Javascript dynamically generated

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Marco Anotnio Ortega
Date: 2009-12-13
Time: 20:52

Javascript dynamically generated

Hello,

I want to load some varialbes from php to the javascript section of the template.

How can this be done?

I was trying something like this:
<script id="source" language="javascript" type="text/javascript">
var d2 = [ [players.KMPlayerIndex;block=option] ];
</script>
And in the PHP side I have:
$TBS->MergeBlock('players',$arrayOfPlayers) ;

Any ideas?
By: Marco Anotnio Ortega
Date: 2009-12-13
Time: 21:06

Re: Javascript dynamically generated

Hi,

I tried the following too:
var d2 = [];
    [b1;block=begin]d2.push([players.KMPlayerIndex]);
    [b1;block=end]


But still doesn't works, I'm getting the complete code in the generated page.
By: Skrol29
Date: 2009-12-13
Time: 21:42

Re: Javascript dynamically generated

Hi,

Try something like this :
$TBS->MergeBlock('players',$arrayOfPlayers) ;

var d2 = [];
d2[[players.KMPlayerIndex]] = '[players.KMPlayerName;block=_]';
By: Marco Antonio Ortega
Date: 2009-12-14
Time: 03:15

Re: Javascript dynamically generated

Thanks, looks shorter, I'll try it when I return to the office.

It worked like this:
PHP:
$TBS->MergeBlock('b1',$arrayOfPlayers) ;
Template:
<script id="source" language="javascript" type="text/javascript">
var d2 = [];
[b1;block=begin]d2.push([b1.KMPlayerIndex]);
[b1;block=end]
</script>