Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
35
rated 0 times [  39] [ 4]  / answers: 1 / hits: 23209  / 11 Years ago, mon, may 13, 2013, 12:00:00

Is it possible to get the value of the text in an anchor tag when the link is clicked? e.g
if you have <a href=#>Tables</a>
is it possible to retrieve the value Tables in a variable like a session variable and use it across your pages?
I have several categories of items(which are links) and i want to be able to get the value of any category clicked and use it pull products listed in that category from my database.
Thanks.



EDIT:
This what i tried
<a href=# onclick= <?php $_SESSION[value] = Table ?>>Table</a>
But didn't get the value.
Apologies, should have posted it earlier


More From » php

 Answers
148

As posted, your code does not submit so your PHP is never processed:



<a href=#


When you have # as the href value, no new request is submitted. However, you can modify your anchor to submit the category back to your PHP script like this:



<a href=yourscript.php?category=Table>Table</a>


Then in yourscript.php you can read the value using $_GET:



$selected_category = $_GET['category']; // Get 'Table'


To set the value in your session, first be sure that you have started your session near the top of your script:



session_start();


then save the value like this:



$_SESSION['selected_category'] = $_GET['category'];

[#78256] Sunday, May 12, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hanna

Total Points: 66
Total Questions: 99
Total Answers: 101

Location: Saudi Arabia
Member since Sat, Aug 20, 2022
2 Years ago
;