July 14, 201115 yr When the user clicks div_button, I want a PHP script to execute, but this doesn't work (obviously)... <div id="div_button" onClick="<?php scriptname('hello'); ?>"> Click me! </div> Is there a method or trick to execute PHP from javascript? Edited July 14, 201115 yr by Davve
July 14, 201115 yr PHP is a pre hypertext text processor that means it makes the html before the browser gets it. no php code would reach the client so thats why its not working. javascript is what you use to do things after the page has been sent, onClick is a javascript handler. I recommend taking alook at jQuery and a method called Ajax... what you do is get jQuery to wait for the onClick event and then send a request back to your server where you can then run some php code, create some html and send it back.
Create an account or sign in to comment