Jump to content

Onclick PHP script


akrytus

Recommended Posts

If you want to run a PHP scriupt when you click a link/button/image without the user being sent to the PHP script itseft you'll want to use AJAX. AJAX is javascript, but it allows you to called server side scripts in the background without having to reload the page. Check out [url=http://www.ajaxfreaks.com/tutorials/1/0.php]this introduction[/url] tutorial over at ajaxfreaks.com
Link to comment
Share on other sites

I appreciate the link and help.  I submitted help into the forums, and no one seems to respond.  Not nearly as many user as this forum.  I looked at many examples and tutorials and cant seem to find what I need.  Perhpas you could give me some pointers  if you do not mind.  Thankyou much!
Link to comment
Share on other sites

Alright check this out, I am racking my brain here and this is a very difficult concept to understand and accomplish in my opinion.  Let me re-explain.

The only way I know how to send client side information to a server is through a form.  This is slow and clumsy to me, I want to use links that are created when a page loads through a php script.  These links are dynamic so I cant just create these myself, they must be created through a script.
  When you click a link, I need to know which link was clicked so I can send that data to a php script.  Using Ajax, only allows you to run php script to send Ajax data without a refresh, not the other way around.  You cannot send a php script data from Ajax, or any javascript that I am aware of.

Am I truely limited to using a form or is there a way that I am not aware of using either Ajax or any other method? 

Link to comment
Share on other sites

Output:

  Link1
  Link2
  Link3


User:

Click Link1 -> Send the data that tells the php script that link1 was clicked.


PHP:

Sees link1 was clicked therefore do this;


Its like choosing from a dynamic drop down menu in a form.  But instead I want to use links.  Without using a form, I dont know how to send what was chosen by the user to the php script.  What it does is irrelevant, what it does depends on what link was chosen.  Again the links are dynamic so I cant predefine what it does, it must create it all on its own.


Link to comment
Share on other sites

What I'm trying to establish is whether you want the browser to relocate to the script being clicked on. If so, that's easy: just add a query string on the end of the URL, e.g.
[code]
<a href="myscript.php?var1=1&var2=10&var3=20">My link</a>
[/code]

and you then get the values in the PHP script in the $_GET array, just like you get them from a form using the $_POST array.

If you don't want to relocate the browser to the script, but just want to call it, there is a way to do it with Javascript (or even without the javascript but in a less useful way).
Link to comment
Share on other sites

You guys are brilliant, I appologize to Wildteen88, I just didnt understand it in your example, but you were right.  I never thought about sending it through the URL like that, I am so stupid.  Still learning.  Thankyou for your help everyone. 
Link to comment
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.