tipiwiny
tipiwiny

Reputation: 409

Detect and store clicked linked inside a div

My idea is this: a div contains a dynamic number (from 1 to N) of links. When I click any link, all redirect to "nextpage.php". I would like to store the clicked link and then recover his name.

<div class="myclass">
    <a href="nextpage.php" name="name1">Value 1</a>
    <a href="nextpage.php" name="name2">Value 2</a>
    <a href="nextpage.php" name="name3">Value 3</a>
    .
    .
    .
    < href="nextpage.php" name="valueN">Value N</a>
</div>

For example, if i click on Value3 , I will be redirected to nextpage.php and I will need recover Value3. I should use javascript to implement this? Thank for you help.

Upvotes: 0

Views: 63

Answers (1)

AlmasK89
AlmasK89

Reputation: 1340

No, you don't need any javascript. Use GET variables.

HTML:

<div class="myclass">
<a href="nextpage.php?name=value1" name="name1">Value 1</a>
<a href="nextpage.php?name=value2" name="name2">Value 2</a>
<a href="nextpage.php?name=value3" name="name3">Value 3</a>
.
.
.
<a href="nextpage.php?name=valueN" name="valueN">Value N</a>
</div>

PHP:

<?php 
if (isset($_GET['name']){
    $name = $_GET['name'];
}else{
    $name = 'Default value';
}

Upvotes: 1

Related Questions