execute a php function when text is clicked [Solved]

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

someguy4
Forum Newbie
Posts: 6
Joined: Wed May 09, 2007 9:55 pm

execute a php function when text is clicked [Solved]

Post by someguy4 »

wanted to know to execute a php function you click on some text
Last edited by someguy4 on Thu May 10, 2007 6:13 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Can you be more specific?
thamizhchelvan
Forum Newbie
Posts: 23
Joined: Tue May 08, 2007 2:50 am

Re: execute a php function when text is clicked

Post by thamizhchelvan »

someguy4 wrote:wanted to know to execute a php function you click on some text

I think you are going to execute like JavaScript functions?.Note that you cannot do event handling using PHP. You can use AJAX for execute a PHP function in a remote page.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

How about doing in a simple way by making a query string by calling javascript function. When you click some word, just invoke a js functiion which will reload the page with string attached to the URL.

Suppose, when you click a word x. reload the page like http://xyz.com?word=x. I guess that will make a sense.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

dibyendrah wrote:How about doing in a simple way by making a query string by calling javascript function. When you click some word, just invoke a js functiion which will reload the page with string attached to the URL.

Suppose, when you click a word x. reload the page like http://xyz.com?word=x. I guess that will make a sense.
How does that make it simple?

Code: Select all

<a href="?word=x">x</a>


Anyways, we need more details. People are just guessing at what you want because the request makes no sense.
User avatar
linkmania
Forum Newbie
Posts: 4
Joined: Thu May 10, 2007 1:45 am
Location: India

Re: execute a php function when text is clicked

Post by linkmania »

someguy4 wrote:wanted to know to execute a php function you click on some text

I am also expecting for a good solution
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

d3ad1ysp0rk wrote:
dibyendrah wrote:How about doing in a simple way by making a query string by calling javascript function. When you click some word, just invoke a js functiion which will reload the page with string attached to the URL.

Suppose, when you click a word x. reload the page like http://xyz.com?word=x. I guess that will make a sense.
How does that make it simple?

Code: Select all

<a href="?word=x">x</a>


Anyways, we need more details. People are just guessing at what you want because the request makes no sense.
Oh well, from the query string, you can take the word and do whatever you like. I have written from my knowledge and I know better solutions are yet to come in this thread. I just took a participation hoping it will help someone.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Search for Ajax on these forums or as dibyendrah stated have a javascript onclick event send information to reload the page (methods exist for either get or post), during which the PHP code would need to processed.

Note: PHP/Webserver is server side which sends the page to the clients Browser. Once the browser has the page and the user can access it (example click on it) you are restricted to using client side techniques such as javascript unless you pass information back to the webserver/php again (form submit or via javascript ajax are two possible alternatives).
someguy4
Forum Newbie
Posts: 6
Joined: Wed May 09, 2007 9:55 pm

Post by someguy4 »

well....

if you click on the text "bob" for example, it will run the function ChangeValues() that is specifyed in php
User avatar
tvs008
Forum Commoner
Posts: 29
Joined: Wed May 03, 2006 10:46 pm
Location: Seattle

Post by tvs008 »

you dont need to use javascript or ajax if you are ok with refreshing the page as usual.
someguy4
Forum Newbie
Posts: 6
Joined: Wed May 09, 2007 9:55 pm

Post by someguy4 »

trying to do this

Code: Select all

echo "<script type="text/javascript"><a onclick="ChangeValue()">clickhere</a></script>";

but get this error


Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'


did i do it right?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

You REALLY need to step away from the editor and either buy a book or read an introduction tutorial on PHP. You're missing the concept of server side vs client side and what each is used for..
someguy4
Forum Newbie
Posts: 6
Joined: Wed May 09, 2007 9:55 pm

Post by someguy4 »

then can u tell me what i need to do to make this work?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

No. What you're proposing doesn't make sense. Like I said, start from the beginning, go read a beginner's tutorial.
someguy4
Forum Newbie
Posts: 6
Joined: Wed May 09, 2007 9:55 pm

Post by someguy4 »

alright fine
Post Reply