I am trying to pass values from option panel to use them on jQuery setting value everything working except true
or false
SO How can I convert it or use it right way.
What I am trying where $offers_animation_type = true
its return true
but not working as like if direct write true
or false
in the option value.
$("#Ticker").breakingNews({
effect :"slide-v",
autoplay :<?php echo $offers_animation_type;?>,
timer :<?php echo $offers_animation_change;?>,
color :"turquoise",
border :true
});
But it should be like
$("#Ticker").breakingNews({
effect :"slide-v",
autoplay :true,
timer :3000,
color :"turquoise",
border :true
});
In PHP printing true
will result 1, but printing false
will not print anything. So when the value was false
, you broke the JS code. (autoplay:,
)
$("#Ticker").breakingNews({
effect :"slide-v",
autoplay :<?php echo $offers_animation_type ? "true" : "false";?>,
timer :<?php echo $offers_animation_change;?>,
color :"turquoise",
border :true
});
you can use ternary operator in php like this
$("#Ticker").breakingNews({
effect :"slide-v",
autoplay :<?php echo ($offers_animation_type): 'true'? 'false'; ?>,
timer :<?php echo ($offers_animation_change): 'true'? 'false'; ?>,
color :"turquoise",
border :true
});
$("#Ticker").breakingNews({
effect :"slide-v",
autoplay :<?=(isset($offers_animation_type) && !empty($offers_animation_type))? 'true' : 'false'; ?>,
timer :<?=(isset($offers_animation_change) && !empty($offers_animation_change))? $offers_animation_change : 3000; ?>,
color :"turquoise",
border :true
});