I would like to change the value of a PHP variable when a specific div is clicked on. 
The only way I can see this is possible is by somehow refresh the webpage, so it can read the variable again, But I do not need to refresh the whole page, i only need to refresh some of it. 
Also the onclick needs to execute 2 things.
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/include/functions.php";
include($path);
randomopponent();
$chosenopponent = "Choose a opponent";
?>
<html>
  <head>
    <link rel="stylesheet" href="include/css/logged_in.css" />
    <title> testsite</title>
  </head>
  <body>
    this is a protected page! <br>
    <a href="#chooseopponent">chooseopponent</a>
    <div id="chooseopponent" class="chooseopponent"> <!-- This is the part that chosses the opponent -->
      <div>
        <h2>choose an opponent</h2>
        <table class="chooseopponenttable">
          <tr>
            <td class="chooseopponenttd" onclick='location.href = "#<?php echo "$opponent1"; ?>"'>
              <?php echo "$opponent1" . "<br>"; ?> <!-- defined in randomopponent(); -->
              <img
                class="chooseopponnetpic"
                src="/<?php echo $opponentpic1; ?>"
                alt="<?php echo "$opponent1"; ?>"> <!-- defined in randomopponent(); -->
            </td>
            <td class="chooseopponenttd" onclick='location.href = "#<?php echo "$opponent2"; ?>"'>
              <?php echo "$opponent2" . "<br>"; ?> <!-- defined in randomopponent(); -->
              <img
                class="chooseopponnetpic"
                src="/<?php echo $opponentpic2; ?>"
                alt="<?php echo "$opponent2"; ?>"> <!-- defined in randomopponent(); -->
            </td>
            <td class="chooseopponenttd" onclick='location.href = "#<?php echo "$opponent3"; ?>"'> 
              <?php echo "$opponent3" . "<br>"; ?> <!-- defined in randomopponent(); -->
              <img
                class="chooseopponnetpic"
                src="/<?php echo $opponentpic3; ?>"
                alt="<?php echo "$opponent3"; ?>" > <!-- defined in randomopponent(); -->
            </td>
          </tr>
        </table>
      </div>
    </div>
    <?php
    echo "<br>";
    echo $chosenopponent;
    ?>
    <div class="logoutbox"> <!-- Logout button -->
      <input
        type="button"
        onclick="location.href = 'index.php?logout';"
        Value="Logout"
        class="logout_button"
        />
    </div>
  </body>
</html>
SO the part I do not know how to do is when for example $opponent3 is clicked the $chosenopponent should now be $chosenopponent = $opponent3 and echo that out.
 
     
    