Calling php function

Hi, I have problem…my php function is not working in the onclick function…why is it not working.can you help me please on this.


function myonclickbutton(){
     var myphpfunc = '<?php echo myfunction();?>';
}



<a title="Save" onclick="myonclickbutton()" href="#" id="mybtn"><


Thank you in advance

How do you expect the client side JavaScript to communicate with your server side php? That’s why you use JavaScript, because you can’t expect users to have php.

But you should be more specific about what you’re trying to accomplish here.

Are you confusing server-side PHP that runs before the page is rendered with client-side javascript that runs after the page has loaded?

Hi,…I want that when i submit the form my php function will be executed in my onclick().

The only way to do that is to send the message to the server, where the PHP function is.

You need either another page load, or to use AJAX. Either way an HTTP request is needed.

Isn’t this related to an older thread of yours?

Ok Thank you…i have some question when i am trying to alert “hello” in my onclick.


function myonclick(){
 var mytest = "<?php echo 'hello';?>";

 alert(mytest);

}

it will alert to this

<?php echo ‘hello’;?>
,it should be hello only without the php tags…

Nope,:slight_smile:

OK, so it’s all about JS?


function myonclick(){
 var mytest = "hello";

 alert(mytest);

}