0

I know this question has been asked, but I can't for the life of me figure out what's going on. I have a very simple onsubmit function that should execute when I run in my html. I have no problem running oninput, but not onsubmit.

The extremely strange thing is, that the exact same html/javascript runs fine in jsfiddle. Any ideas?

    <script type="text/javascript">
        function CheckLogin()
        {
           alert('I should work');   
            return false;
        }
    </script>
    <form name="login" id="login" method="POST" onsubmit="return CheckLogin();">
        <input type="submit" value="Test" name="test" />
    </form>
stevenlacerda
  • 1,187
  • 2
  • 9
  • 21
  • Is It not the browser? https://codepen.io/paulodiogo/pen/NwwNzG –  Nov 16 '17 at 22:24
  • I guess it is a problem of when your `script` is loaded in your html. Maybe you can consider this [answer](https://stackoverflow.com/questions/436411/where-should-i-put-script-tags-in-html-markup) – edkeveked Nov 16 '17 at 22:32
  • 1
    The ordering shouldn't matter in this case, because you are calling a function that is not referencing DOM elements. What are you using for editing and trying this out? – Adjit Nov 16 '17 at 22:33
  • Also, no need to say `onsubmit="return CheckLogin();"` you just need to call the function - `onsubmit="CheckLogin();"` – Adjit Nov 16 '17 at 22:39
  • It works in the SO code snippets also. Can you share how to reproduce the problem you're seeing? i.e. what setup (browser, code input, etc) make it not work? – cstricklan Nov 16 '17 at 22:46
  • Not sure what's going on. If I remove the submit input and add this works fine. I'm on chrome Version 62.0.3202.94 (Official Build) (64-bit). This same browser works on jsfiddle, so I can't imagine that's the issue. – stevenlacerda Nov 16 '17 at 22:57
  • Changed the onsubmit function to foo, and it seems to pick it up: t.onsubmit ƒ onsubmit(event) { foo() } where t is my form element, so I'm not sure why it's never executing. – stevenlacerda Nov 16 '17 at 23:03

0 Answers0