JSFiddle - React, Tailwind, and code Playground

HTML

<input id="Ancre">
<nav>
  <a href="#id1">ancre 1</a>
  <a href="#id2">ancre 2</a>
  <a href="#id3">ancre 3</a>
  <a href="#id4">ancre 4</a>
  <a href="#id5">ancre 5</a>
  <a href="#id6">ancre 6</a>
</nav>
<form action="mapage.php">
formulaire vide juste pour afficher le contenu de l'attribut action
</form>

CSS

form{
  margin:1em;border:inset 2px;
  border-radius:1em;
  padding:1em;
}
form:after {
  content:attr(action);
  display:block;
  color:tomato;
}

JavaScript

function locationHashChanged() {
document.getElementById("Ancre").value= location.hash;
document.querySelector('form[action^="mapage.php"]').setAttribute('action','mapage.php'+location.hash)
}
window.addEventListener('hashchange', locationHashChanged);