Menu
Hello, I understand js is on client side and php is on server side. I am looking for a simple solution to call a php function in javascript
without going throught the fuzz of Ajax, post…
I got a code like this from SO:
[CODE]
<script>
function phpadd() {
var phpadd= <?php add(1,2);?> //call the php add function
alert(phpadd) // result in undefined
}
</script>
<?php
function add($a,$b){
$c=$a+$b;
return $c;
}
?>
<button onclick=’phpadd()’>add</button>
The poster claims it works but it doesn’t for me. And I don’t understand how it would possibly work. Can someone point it out either ways? Thanks.