Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-01-2009, 08:09 PM   PM User | #1
tdavis
Regular Coder

 
Join Date: Feb 2005
Location: Atlanta, GA
Posts: 171
Thanks: 5
Thanked 0 Times in 0 Posts
tdavis is an unknown quantity at this point
PHP functions

why will this not work?

Code:
<?php
function testing_function()
{
echo "THIS IS A TEST";
}
print "<input type='button' value='TEST' onclick='testing_function()'>";
?>
tdavis is offline   Reply With Quote
Old 05-01-2009, 08:19 PM   PM User | #2
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,744
Thanks: 2
Thanked 255 Times in 247 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
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.)
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
CFMaBiSmAd is online now   Reply With Quote
Old 05-01-2009, 08:28 PM   PM User | #3
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,229
Thanks: 2
Thanked 190 Times in 188 Posts
djm0219 is on a distinguished road
The onclick is looking for the JavaScript function named testing_function NOT the PHP function by that name.
__________________
Dave .... HostMonster for all of your hosting needs
djm0219 is offline   Reply With Quote
Old 05-01-2009, 08:57 PM   PM User | #4
tdavis
Regular Coder

 
Join Date: Feb 2005
Location: Atlanta, GA
Posts: 171
Thanks: 5
Thanked 0 Times in 0 Posts
tdavis is an unknown quantity at this point
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?

Code:
<script language='JavaScript'>
function testing_function()
{
alert('test');
}
</script>
<?php
print "<input type='button' value='TEST' onclick='testing_function()';>";
?>
tdavis is offline   Reply With Quote
Old 05-02-2009, 02:45 AM   PM User | #5
venegal
Gütkodierer


 
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
venegal has a spectacular aura aboutvenegal has a spectacular aura about
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.
venegal is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:02 AM.


Advertisement
Log in to turn off these ads.