views:

67

answers:

4

I am new to javascript world.

I wrote a function in PHP. How do I call it when I click a button or image in html?

A: 

You have a general missunderstanding.

PHP is serverside, HTML/JS is clientside.

so if you want to call a server method from clientside you have to execute a request to the server. in modern days this is done via an AJAX request.

Checkout Jquery ajax functions this would be the easiest way.

Rufinus
+3  A: 

If you want to call serverside functions you should use AJAX.

Goto http://www.w3schools.com, and take the AJAX tutorials.

sanjay
A: 

You can't. You have to make a request to a PHP page, usually via AJAX, and then that page has to call the PHP function and return the results.

Ignacio Vazquez-Abrams
A: 

I've written a blog post on this subject not too long ago. It covers most of the techniques you can use to call something on the server.

Jan Hančič