PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Sep 19, 2018 8:56 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed Apr 25, 2018 9:03 pm 
Offline
Forum Commoner

Joined: Fri Aug 14, 2009 9:43 am
Posts: 70
Hello All,
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:

Syntax: [ Download ] [ Hide ]
if(document.getElementById("adon1").checked) {
        var bold = parseFloat(<?php echo $boldFace; ?>);
}


Instead of:

Syntax: [ Download ] [ Hide ]
if(document.getElementById("adon1").checked) {
        var bold = parseFloat(0.55);
}


Is there a way to do this? Or is there a better approach? I've found a bunch of sites that have different versions of this, but none of them work. I've tried with and without parseFloat, I've used quotation marks and without quotation marks, ad nuasium. Any suggestions, tutorials, articles will be much appreciated.
Thanks,
Rick


Top
 Profile  
 
PostPosted: Thu Apr 26, 2018 11:32 am 
Offline
Forum Commoner

Joined: Fri Aug 14, 2009 9:43 am
Posts: 70
Okay I feel really stupid,
It's no wonder this post has yet to draw a response!! Nothing wrong with the use of json_encode() or straight PHP injection "<?php echo $var; ?>;" - it all works fine. I was so tired last night, I didn't realize I failed to turn on the testing server. I must have spent 2 1/2 hours trying to get that to work (I can't believe it). I knew I was very tire, but I didn't know I was that tired.

BTW, is there a technical term for driving ones self to madness?
Thanks anyway,
Rick


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group