Friday, June 27, 2014

How to implement an onClick function in a PHP code

If you are writing a button in HTML such as this:

<button type="button">Click!</button>

And you want to have an onClick function for it, for each something happens in your PHP code, the best way is to use document.write('<?php myFunction() ?>').
This will actually make the button execute the myFunction() function in your PHP code upon clicking on it. So all you have to do is to modify your button such as this:

<button type="button" onclick="document.write('<?php myFunction() ?>');">Click!</button>

Happy coding :)

Sadaf



No comments:

Post a Comment