This question already has an answer here:
Please help me on how to concatenate php code on jquery html:
$('div#divID').html('<?php echo $fib->getFibonacci( " + limit + "); ?>");
in order to pass the value: var limit = $('#inputID').val()
of input after clicking the button. Thank you!
PHP Code
class Fibonacci {
public function getFibonacci($num){
...
return $fib;
}
}
$fib = new Fibonacci();
HTML
<input type="text" id="inputID">
<button id="buttonID">
<div id="divID">
JS
$('#buttonID').click(function() {
var limit = $('#inputID').val();
$('div#divID').html("<?php echo $fib->getFibonacci( " +limit+");?>");
});
Goal: to pass the value on input when calling Php function using jquery syntax. Is there possible way? Thank you.
</div>
In your example you are trying to pass JS variable as argument to PHP function. It is not possible this way, because PHP is server side, and JS is client side (in your case) scripting language. What you can do is on click to calculate "limit" value, pass it using AJAX to "getFibonacci" function in php and to append into html tag returning value. That is one way of interaction between PHP and Front-end JS.