Jump to content

Recommended Posts

[!--quoteo(post=355545:date=Mar 15 2006, 08:52 PM:name=ari_aaron)--][div class=\'quotetop\']QUOTE(ari_aaron @ Mar 15 2006, 08:52 PM) [snapback]355545[/snapback][/div][div class=\'quotemain\'][!--quotec--]
How can I make some text, and when it is clicked, some code is executed?
[/quote]

welcome to the forums. i hope you are able to find lots of help here.

as to your question, you'll have to be a little more detailed, as there are a LOT of ways to do what you're after, but they all approach the idea differently. you can make the text a link and just check with PHP to see if the link has been followed, or you can use AJAX to do something similar without refreshing the page. another option would be to have a hidden form that is submitted when you click the text.

basically, what i'm getting at is you need to define more specifically what you mean by "some code is executed"... what result are you after? what kind of interface are you wanting to keep, etc...

the more detail you can give, the more likely we'll be able to help you come up with a workable solution

good luck
Link to comment
https://forums.phpfreaks.com/topic/5079-click-text/#findComment-18028
Share on other sites

Thank you, I want to have the page run an SQL query and then change a variable. Does refreshing a page clear the POST data that it received? if so, I would not want to do that (although I guess I could pass it on). I would want the new variable to be displayed, though.
Link to comment
https://forums.phpfreaks.com/topic/5079-click-text/#findComment-18188
Share on other sites

[!--quoteo(post=355753:date=Mar 16 2006, 07:52 PM:name=ari_aaron)--][div class=\'quotetop\']QUOTE(ari_aaron @ Mar 16 2006, 07:52 PM) [snapback]355753[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Thank you, I want to have the page run an SQL query and then change a variable. Does refreshing a page clear the POST data that it received? if so, I would not want to do that (although I guess I could pass it on). I would want the new variable to be displayed, though.
[/quote]

$_POST variables are only received when a page is loaded, so i'm not sure what you mean by "clear" the data. if you're looking to have recurrent pages reference the same variable, you'll want to go with session variables, but let's take this one step at a time. copy and paste this code and see if it gives the basic idea of what you're after:
[code]
<?php
$var = isset($_GET['var']) ? $_GET['var'] : 'none';
echo "Value of \$var: <b>$var</b><br />\n";
echo "<a href='?var=blue'>change to \"blue\"</a>\n";
?>
[/code]

that should start out with the output:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
Value of $var: [b]none[/b]
[/quote]

then, when you click on the link, it should refresh as:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
Value of $var: [b]blue[/b]
[/quote]

if you understand the principles, you can easily apply a SQL query where you'd like instead of simply assigning the value to the variable manually.

hope this helps!
Link to comment
https://forums.phpfreaks.com/topic/5079-click-text/#findComment-18337
Share on other sites

The answer if you need to have a hidden input. Example:

You have a form, a user submits the data, and is sent to another form within the same php code. You want to use the data from a previous field, or maybe even 2 or 3 forms back. Use this:

[code]
<input type="hidden" name="something" value="$something">
[/code]

Put that in a form to use that data in the next form, and even if you use it then, you need to use that everytime for the following page/form.

I probably made it more complicated that it really is...but you'll get the idea.
Link to comment
https://forums.phpfreaks.com/topic/5079-click-text/#findComment-18472
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.