How to run a javascript script right after submitting the form? (not onClick)

Asked

Viewed 923 times

1

I want to run a javascript function that shows a message by clicking on the page, that is, while the page loads, the message appears on the screen, but I do not know how to use in Html5 with javascript, because I am using the required(validation within html, without js)

I’ve heard of the function onbeforeunload, but it is discontinued, has some function that replaces it?

  • onbeforeunload not this depreciated

1 answer

0


"How to run a javascript script right 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

  • opa, thanks, that’s what I wanted, put it exactly like this '<form name="Form1" method="post" action="processing.php" onsubmit="Return gifCarregando();">' along with the JS so 'Function gifCarregando(){ $('#wait, #Blanket'). css('display','block'); Return true; };' and it worked, thanks, :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.