Calling a function on click of button in HTML/PHP [closed]

You should use Ajax/XmlHTTPRequest for this. I’d suggest following a tutorial on Mootools or jQuery for this.

The general procedure will be to attach a click event to the button:

<button onclick="doMyThing()">Click here!</button>

Then inside the JS function doMyThing you set up a call using Mootools or jQuery (click either for samples and documentation) to your serverside PHP script. In the success function of the request you can then process the results.

You could do the same without using a JS library, but you’d have to handle browser-specific intricacies of XMLHttpRequest yourself.

Browse More Popular Posts

Leave a Comment