How to change php Session variables after checkbox click

As stated, I have a website written in php with a checkbox and I’m trying to store its state between pages. Maybe it’s me being still new to javascript and php but I cannot get it to work

Below is my code (simplified):

one.php:

<?php session_start(); ?>
<html>
  <head>        
    <script>
        checkbox = document.getElementById('vehicle_toggle');
        checkbox.addEventListener('change', e => {
            if(e.target.checked){
                $_SESSION["favcolor"] = "red";
            } else {
                $_SESSION["favcolor"] = "green";
            }  
        });      
    </script>        
  </head>
  <body>
    <?php
      $_SESSION["favcolor"] = "red";
      print_r($_SESSION);
    ?>
    <input type="checkbox" id="vehicle_toggle" name="vehicle_name" value="Bike"  checked="checked">
    <label for="vehicle_toggle" class="vehicle_label">bike</label><br>        
    <a href="two.php">two</a>
  </body>
</html>

two.php:

<?php session_start(); ?>
<html>
  <body>
    <?php echo "Favorite color is " . $_SESSION["favcolor"] . ".<br>"; ?>
  </body>
</html>

No matter the state of the checkbox on “one.php”, the color/state that is stored (and therefore printed for “two.php”) is the initial “red”. I’ve tried several different ways to write the javascript snippet but the output is always the same.

Thank your for your help!