JSFiddle - React, Tailwind, and code Playground

HTML

Escape field value, enter ampersand for example and click outside ("onchange")
<form method="POST">
  <input type="text" id="the-field">
</form>

JavaScript

function escapeIt() {
  var encodedField = encodeURIComponent(document.getElementById("the-field").value),
    decodedField = decodeURIComponent(encodedField);
    document.getElementById("the-field").value = decodedField;
//  alert("encoded: '" + encodedField + "', decoded again: '" + //decodedField + "'");
  alert(document.getElementById("the-field").value);
}
// normally "onchange" attribute in the input field, doesn't work here, jsfiddle problem i guess...
document.getElementById("the-field").addEventListener("change", escapeIt);