...

View Full Version : PHP functions



tdavis
05-01-2009, 08:09 PM
why will this not work?



<?php
function testing_function()
{
echo "THIS IS A TEST";
}
print "<input type='button' value='TEST' onclick='testing_function()'>";
?>

CFMaBiSmAd
05-01-2009, 08:19 PM
Php is parsed and executed on the web server at the time the page is requested. onclick events occur in the browser. You cannot "call" php functions from the browser. The browser can only make http requests to web servers (i.e. request pages through their URL.)

djm0219
05-01-2009, 08:28 PM
The onclick is looking for the JavaScript function named testing_function NOT the PHP function by that name.

tdavis
05-01-2009, 08:57 PM
Right. The following does work. But what I really want to do is save some session information. But I guess that is not possible in JavaScript, is it? Or can that be done using Ajax?



<script language='JavaScript'>
function testing_function()
{
alert('test');
}
</script>
<?php
print "<input type='button' value='TEST' onclick='testing_function()';>";
?>

venegal
05-02-2009, 02:45 AM
It depends on how you want to handle your session information. In Javascript you can do it with cookies alright, but handling that stuff server side is probably cleaner.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum