javascript - addEventListener() Not Working - can't figure out why -


wrote super basic script try out addeventlistener , it's not working ...

why?

here's code:

<html>     <head>         <meta charset="utf-8" />         <title></title>          <script>              function validateme(){                  document.getelementbyid("button1").addeventlistener("click",validateform);                   function validateform(){                     alert("wheeeeee!");                 }                  window.addeventlistener("load",validateme);              }          </script>     </head>     <body>          <form name="" id="" action="" onsubmit="return validateme">                 first name: <input type="input" name="first_name" id="first_name" />                 <br /><br />                 last name: <input type="input" name="last_name" id="last_name" />                 <br /><br />                 email address: <input type="input" name="email" id="email" />                 <br /><br />                 <input type="submit" value="validate" id="button1" />         </form>      </body> </html> 

it seems you're trying add function within function itself. function not executed, therefore not added. try moving addeventlistener statement outside of function block. or, make function anonymous , declare inside addeventlistener call.

edit: see executed on submit. load phase has passed adding @ point won't anything.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -