0

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.

Marcus
  • 822
  • 1
  • 8
  • 27
tipiwiny
  • 399
  • 1
  • 3
  • 18
  • 2
    Use `sessionStorage`...`$(this).attr('name')` or if you want to use this `name` in the next page then use `queryString argument(?name=name3)` – Rayon Apr 05 '16 at 09:37
  • Why you can't try it with query string like as nextpage.php?name=value2 – kannan Apr 05 '16 at 09:39
  • POST or GET method. Or session variable. – Andreas Apr 05 '16 at 09:40
  • SessionStorage, cookies, localStorage... Here a good guide too: http://stackoverflow.com/questions/19867599/what-is-the-difference-between-localstorage-sessionstorage-session-and-cookies – JP. Aulet Apr 05 '16 at 09:40
  • thanks for your comment! I have used GET variables. – tipiwiny Apr 05 '16 at 10:06

1 Answers1

1

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';
}
AlmasK89
  • 1,332
  • 7
  • 16