Reputation: 660
Is there a way to get a certain value and store it in a variable when an anchor linked to a div is clicked?
Like if I have two links like
<a href="#one">One</a>
<a href="#two">Two</a>
Would I be able to somehow get if the user clicked one
or two
and store it in a PHP variable?
Upvotes: 0
Views: 730
Reputation: 409
Take Praveen Kumar's solution and change the HTML part this way to keep anchors working:
<a href="?name=one#one">One</a>
<a href="?name=two#two">Two</a>
Upvotes: 0
Reputation: 167182
Yes, you can add them as a GET
request and store it in the session. Change your code this way:
<a href="?name=one">One</a>
<a href="?name=two">Two</a>
And in the PHP, you can do this way:
<?php
session_start();
$_SESSION["name"] = $_GET["name"];
?>
Upvotes: 1