Search code examples
htmlserver-side

Changing text content depending on button clicked


I am sort of a beginner at this, but my objective is to have the header of my webpage changing, depending on what button was clicked on another page.

More precisely, I have a webpage with 7 buttons on it coded like this:

<form action="contribution.html">
    <input type="submit" style="margin-right: 80px;margin-top: 25px;" value="I contribute">
</form>

All of the buttons lead to the same "contribution.html" page, but I would like the header of that page to be different depending on what button the user clicked. There must be a way to do this without creating 7 different "contribution.html" pages for each button... I assume.

Can anyone help, please?


Solution

  • Use a server-side language and <a> tags instead of a form. In PHP it will look something like this:

    <a href="/contribution.php?sum=10">10$</a>
    <a href="/contribution.php?sum=20">20$</a>
    <a href="/contribution.php?sum=30">30$</a>
    

    etc.

    Then on contribution.php you can get the request data from $_GET['sum'] and act accordingly.