0

I want to get the text of an anchor tag when the user clicked on it. and I also want to store that text inside PHP variable.this should be implemented through using javascript and PHP . (no jquery)

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

The problem in your request is, that php is serversided, which means that at the time your user presses an anchor tag, the php already finished loading

RPaul
  • 66
  • 7
  • the text which I'm talking about is stored in the database. for example, It is name of the topic . and after a user clicked on topic I want fetch the content of that topic ..that's why I need the name of the topic. sorry for my bad english I hope you will understand. – HITESH ALONEY Aug 06 '16 at 08:07
  • So if I understood you correctly, you want to fetch a text to put into a php variable when the anchor tag is pressed. You might need to tell me what you want to do with the php variable, but judging from how this sounds, you might need to use jquery->ajax – RPaul Aug 06 '16 at 08:12
  • It sounds like you need to use JSON/AJAX if I understand what you're trying to do correctly. – JBartus Aug 06 '16 at 08:13
  • I don't want to use JSON/AJAX or Jquery.only javascript and PHP.I want to use that PHP varible to fecth content from the database for example, select content from topics where unique_topic=that_achor_text_name_In PHP_VARIABLE; – HITESH ALONEY Aug 06 '16 at 08:19
  • I'm afraid you cannot achieve this without jquery unless you get all the data from the database in the php while loading the site, which u can then pass on to the javascript part. I'm just guessing you want to display the content, which shouldn't be a problem then – RPaul Aug 06 '16 at 08:27
  • try firing up the query in your php and loop through the result to create an array. you then pass on the array to javascript with var array = ; You can the search for your data in that array as soon as an anchor tag is pressed – RPaul Aug 06 '16 at 08:34
  • Thanks for your answer I will try it. – HITESH ALONEY Aug 06 '16 at 13:05