I have a javaScript function I'm developing. It works when I hard code the variables into the function, but I want to inject PHP variables into the JS. The PHP values within the variables are simple scalar data, floating point numbers: 0.55 and 0.75 respectively.
The user will be able to select ad-on features if he / she decides, although the default is none. I need to be able to use the PHP variables, as there will be dozens of these functions throughout the site. I've used straight PHP and json_encode within the var declaration, without success. Maybe this instance requires a different syntax and it may not work at all within a JS function, although I've found sites that claim this works.
What I would like to do is something like this:
Code: Select all
if(document.getElementById("adon1").checked) {
var bold = parseFloat(<?php echo $boldFace; ?>);
}
Code: Select all
if(document.getElementById("adon1").checked) {
var bold = parseFloat(0.55);
}
Thanks,
Rick