onclick="RELOAD PHP FUNCTION()"; How???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
imsoconfused
Forum Newbie
Posts: 15
Joined: Mon Oct 05, 2009 10:55 pm

onclick="RELOAD PHP FUNCTION()"; How???

Post by imsoconfused »

Hello Everyone,

I have a php script that creates a calender with the current month year. I want to add 2 buttons. One is to go back 1 month and 1 is to go forward one month

I have encapsulated the calender as cal();

When the function is called again it will add or subtract one from the month property. the problem is getting the function to reload when the user clicks the previous or the next button. :cry:

I am trying to give the buttons onclick attributes

<input type="submit" value="prev" onclick="cal()";>

This code doesn't work obviously. I rather not have to add javascript or ajax. there should be a way to do this in php!


thanks for your time,


imsoconfused,
sincerely
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: onclick="RELOAD PHP FUNCTION()"; How???

Post by Mirge »

onclick is a javascript event.

Just change the URL to the php script that will handle adding or subtracting a month.

IE: foo.php?month=November&year=2009
John.Mike
Forum Newbie
Posts: 18
Joined: Fri Sep 04, 2009 11:43 pm
Location: Canton.China

Re: onclick="RELOAD PHP FUNCTION()"; How???

Post by John.Mike »

hi,imsoconfused. PHP's server side language,suggest that use the javacript to do this... :)
imsoconfused
Forum Newbie
Posts: 15
Joined: Mon Oct 05, 2009 10:55 pm

Re: onclick="RELOAD PHP FUNCTION()"; How???

Post by imsoconfused »

Ok I am not sure how to do what you were saying, and I am new to PHP so I take back my Javascript comment.

I broke down the concept as much as possible.

All I want is to be able to click the submit button input and it in return triggers the function doThis();

how is this concept done in php/javascript/css/html
?

Code: Select all

 
function doThis()
{
    $Sally = 5;
    echo $Sally;
}
echo "<input name='submit' type='submit' value='prev' onclick='doThis()'></input>";
 
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: onclick="RELOAD PHP FUNCTION()"; How???

Post by Mirge »

You're trying to treat a PHP function as a Javascript function. That is not going to happen. PHP is server-side, Javascript is client-side.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: onclick="RELOAD PHP FUNCTION()"; How???

Post by jackpf »

*sigh*
imsoconfused
Forum Newbie
Posts: 15
Joined: Mon Oct 05, 2009 10:55 pm

Re: onclick="RELOAD PHP FUNCTION()"; How???

Post by imsoconfused »

Ok so what does someone do in a situation where they need to call a php function on user input?
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: onclick="RELOAD PHP FUNCTION()"; How???

Post by Mirge »

Mirge wrote:onclick is a javascript event.

Just change the URL to the php script that will handle adding or subtracting a month.

IE: foo.php?month=November&year=2009
This is what you can do.

Though I'd really recommend grabbing a good PHP book & learning it before you try to tackle anything further.
imsoconfused
Forum Newbie
Posts: 15
Joined: Mon Oct 05, 2009 10:55 pm

Re: onclick="RELOAD PHP FUNCTION()"; How???

Post by imsoconfused »

The problem that I have with doing that is that it reloads the whole page..
User avatar
desperado
Forum Commoner
Posts: 46
Joined: Wed Dec 10, 2008 8:49 am

Re: onclick="RELOAD PHP FUNCTION()"; How???

Post by desperado »

that's what it's supposed to do. it should reload the script from the server according to any new variable you pass along in the URL string.
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: onclick="RELOAD PHP FUNCTION()"; How???

Post by JNettles »

You're looking for an event driven solution to PHP - something more similar to how desktop application programming behaves. To achieve something like this you'll either have to develop your own event-driven architecture complete with Ajax and a system for handling page-state, something I'm going to guess is beyond the scope of your PHP abilities right now.

Look into PRADO if you want an event-driven framework like what you're describing. http://www.pradosoft.com
Post Reply