-1

Hello guys i'm wondering , i was write a good code JS and wondering how or why doesn't work. I will give you all code here:

<script type="text/javascript">
      function submit() {
         alert('Process have done!');
      }
      function reset() {
         alert('Reset Done!');
      }
</script>
<form action="JSEvents.html" method="POST" onsubmit="submit()" onreset="reset()">
      <input type="text" ><br />
      <input type="submit" value="Done" > -
      <input type="reset" value="Reset" >
</form>

5
  • 1
    Could be anything. But keep in mind that you need to put your script at the bottom of the page just before the closing body tag and not before your HTMLand well in the document ready function. Commented Dec 26, 2015 at 21:38
  • @Franco Even then it didn't work. Commented Dec 26, 2015 at 21:40
  • Of course not. You are using a function which will not be called, because the form action has the execution precedence over the javascript. Have a look here: jsfiddle.net/obuybm1h Commented Dec 26, 2015 at 21:44
  • Can you elaborate on "doesn't work"? Commented Dec 26, 2015 at 22:28
  • @WaiHaLee i found the error thank you Commented Dec 27, 2015 at 12:49

2 Answers 2

3

You need to rename your functions. The names "reset" and "submit" are reserved. Try this:

<script type="text/javascript">
      function submitFunc() {
         alert('Process have done!');
      }
      function resetFunc() {
         alert('Reset Done!');
      }
</script>
<form action="JSEvents.html" method="POST" onsubmit="submitFunc()" onreset="resetFunc()">
      <input type="text" ><br />
      <input type="submit" value="Done" > -
      <input type="reset" value="Reset" >
</form>
Sign up to request clarification or add additional context in comments.

Comments

0

The functions submit() and reset() are inbuilt functions. When you call these from your form events you are actually calling the inbuilt ones rather than the ones you defined. The code works but your alerts are not shown. Hence, you need to rename them.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.