Can we call a php function on html buttons onClick event?

I am Suffering fom a problem.
i want to execute particular php code when a button is clicked . So i write a function and called on the onclick event of a Button. But it wont Work.As in Java Script we can call javascript Function on the onclick event.Thats why i try it.
Please Help me if any can........      

Who is Participating?
JonzaConnect With a Mentor Commented:
you cant access the php code directly from form but it sure works if you make the onclick event to submit your form.

----- test.php -----
 function myFunction(){
   print("Yeah, this is my function!!<br>");

if(isset($execute) && $execute == 1){

<input type='button' onclick="window.location='test.php?execute=1';" value='Event'>

that should trigger the myFunction() =)
what are you trying to do nitish i hope i can help you, pls post your complete query, this is kapil.
The short answer is that you cannot directly call a PHP script from an HTML page as you can a JavaScript.  The reason is that PHP is a server side script language, while JavaScript is client side.

With that said, there are a couple of possible work arounds depending on what you are trying to do.  Could you give me a little more information about what you are trying to accomplish?

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Nilesh_KAuthor Commented:
Thanks Joza it is a great Idea.
You Help me allot thanks once again
no problem =)
Nilesh please accept Jonza's comment and the answer.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.