D
D
Dutymy2021-07-09 03:09:41
JavaScript
Dutymy, 2021-07-09 03:09:41

Why onsubmit="return false;" stops the form but onsubmit="sub()" doesn't?

Hello, I have a form with a ban on submitting data and updating the page

<form action="" onsubmit="return false;">
  <input type="text" required id="test" >
  <button type="submit">send</button>
</form>

but by making a call return false;through a function, nothing works - why does this happen
<form action="" onsubmit="sub()">
  <input type="text" required id="test" >
  <button type="submit">send</button>
</form>
<script>
  function sub() {
  return false;
  }
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2021-07-09
@Dutymy

The code in quotes is actually the body of the handler function, the important thing is what will be returned from it. <form action="" onsubmit="return sub()">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question