• 0

[JS] Use a link to change a variable and reload page?


Question

As part of a continuing project that I have been working on here. I have a page that when a variable is changed will display different information. What I would like to be able to do is Click a link on that page that would reload the page using a value based on that link.

Here is a clip, the 8 is the variable that needs changed. I would like it so that each link will have a corresponding number such as Link 1 when clicked would change the number to a "1" and so on. So when the page reloads it will then have a "1" in place of the "8" or what have you depending on which link you click.

Is such a thing easily done?

The page is written using PHP if it matters. Just assumed it would be done using Java Script.

<a href="#">LINK 1</a> | <a href="#">LINK 2</a>

echo $data->dump(false,false,8); ?>

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

I attempted creating a new php variable

$page

and using the click so that onclick $page=1

however that did not work.

Link to comment
Share on other sites

  • 0

Figured it out

<?php
$page = htmlentities($_GET['page']); 
echo $data->dump(false,false,$page);
?>

Then use the following for links.

<a href="<?php echo($_SERVER['PHP_SELF'] . '?page=1'); ?>Link Text</a>

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.