Categories > TinyButStrong general >

Conditional display of javascript parameters

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Jorge
Date: 2010-05-06
Time: 13:37

Conditional display of javascript parameters

Hi.

How could I show a different block of javascript depending on a php variable?

My php variable is $value so i would like to show:

var a = {parameter1: 'value1'};

or

var a = {parameter1: 'value2'};

depending on $value == 1 or $value == 2

Thanks!
By: Skrol29
Date: 2010-05-06
Time: 13:40

Re: Conditional display of javascript parameters

Hi Jorge,

assuming $value  is global:

var a = {parameter1: 'value[onshow.value]'};
By: Jorge
Date: 2010-05-06
Time: 13:43

Re: Conditional display of javascript parameters

Thanks for your quick answer.

I think i didn't express my question very well.

I have a php variable $option. That variable can be 0 1 or 2.

Depending on that value I have to show a block of javascript for loading an flash object.
By: Skrol29
Date: 2010-05-06
Time: 14:15

Re: Conditional display of javascript parameters

Hi,


It can be
if ('1'=='[onshow.option') {
  // here the JavaScript that load the flash object
}

Or
[onshow;block=begin;if [var.option]=1]
  // here the JavaScript that load the flash object
[onshow;block=end]
By: Jorge
Date: 2010-05-06
Time: 14:34

Re: Conditional display of javascript parameters

If tried this with no luck

[onshow;block=begin;if [var.option]=1]
  alert('[var.option]');
[onshow;block=end]
               
[onshow;block=begin;if [var.option]=0]
  alert('[var.option]');
[onshow;block=end]
By: Jorge
Date: 2010-05-06
Time: 14:44

Re: Conditional display of javascript parameters

Ok... i changed the 'if' with a 'when' and now it's working.

Thank you very much Skrol29
By: Skrol29
Date: 2010-05-06
Time: 14:52

Re: Conditional display of javascript parameters

You're right, sorry, it should be a 'when', not a 'if'
'if' is for TBS fields, 'when' is for TBS blocks.