Page 1 of 1
onclick="RELOAD PHP FUNCTION()"; How???
Posted: Thu Oct 08, 2009 2:49 pm
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.
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
Re: onclick="RELOAD PHP FUNCTION()"; How???
Posted: Thu Oct 08, 2009 3:27 pm
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
Re: onclick="RELOAD PHP FUNCTION()"; How???
Posted: Thu Oct 08, 2009 11:40 pm
by John.Mike
hi,imsoconfused. PHP's server side language,suggest that use the javacript to do this...

Re: onclick="RELOAD PHP FUNCTION()"; How???
Posted: Fri Oct 09, 2009 1:43 pm
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>";
Re: onclick="RELOAD PHP FUNCTION()"; How???
Posted: Fri Oct 09, 2009 1:49 pm
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.
Re: onclick="RELOAD PHP FUNCTION()"; How???
Posted: Fri Oct 09, 2009 1:51 pm
by jackpf
*sigh*
Re: onclick="RELOAD PHP FUNCTION()"; How???
Posted: Fri Oct 09, 2009 2:01 pm
by imsoconfused
Ok so what does someone do in a situation where they need to call a php function on user input?
Re: onclick="RELOAD PHP FUNCTION()"; How???
Posted: Fri Oct 09, 2009 2:07 pm
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.
Re: onclick="RELOAD PHP FUNCTION()"; How???
Posted: Fri Oct 09, 2009 2:50 pm
by imsoconfused
The problem that I have with doing that is that it reloads the whole page..
Re: onclick="RELOAD PHP FUNCTION()"; How???
Posted: Fri Oct 09, 2009 2:55 pm
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.
Re: onclick="RELOAD PHP FUNCTION()"; How???
Posted: Fri Oct 09, 2009 3:16 pm
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