I am trying to call JavaScript function with parameter that are PHP variables. I have tried 2 approaches.
calling JavaScript function in PHP with script tag
I found some really good examples on Calling a javascript function from php and it appears you can also run the code online at PhpFiddle.org
Just in case the links break, here are the examples:
Example 1: Calling without parameters
Full example at: http://www.hoverdroids.com/2015/06/10/calling-a-javascript-function-from-php/";
echo "Add whatever PHP you want here...
";
?>
Example 2: Calling with a single parameter
Full example at: http://www.hoverdroids.com/2015/06/10/calling-a-javascript-function-from-php/";
echo "Add whatever PHP you want here...
";
//Data that is going to be passed into the JavaScript function. Try to keep all vars together so
//that it's easier to track down the php/javascript interaction
$jsdata = 'MyName';
?>
Example 3: Calling using an array of parameters
Full example at: http://www.hoverdroids.com/2015/06/10/calling-a-javascript-function-from-php/";
echo "Add whatever PHP you want here...
";
$myname = 'MyName';
$yourname = 'YourName';
//Data that is going to be passed into the JavaScript function. Try to keep all vars together so
//that it's easier to track down the php/javascript interaction
$jsdata = array(
'input' => $myname,
'array_input' => array(
'name' => $yourname
),
);
?>