How to execute a javascript script shortly after sending the form? (other than onClick)

1

I want to execute a javascript function that shows a message loading on the page, ie while the page loads, the message appears on the screen, however I do not know how to use it in html5 with javascript, as I am using required (validation within html, without js)

I've heard of the onbeforeunload function, but it's discontinued, does it have a function that replaces it?

    
asked by anonymous 23.02.2017 / 14:22

1 answer

0

"How to run a javascript script shortly after submitting the form?"

Event onsubmit .

<html>
<script>
function reg() {
  window.captureEvents(Event.SUBMIT);
  window.onsubmit = hit;
}

function hit() {
  console.log('hit');
}
</script>

<body onload="reg();">
<form>
  <input type="submit" value="submit" />
</form>
<div id="d"> </div>
</body>
</html>

Documentation and example

    
23.02.2017 / 14:26