Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #21433

Reset not working when I use addEventListener

From "Tony Johansson" <johansson.andersson@telia.com>
Newsgroups comp.lang.javascript
Subject Reset not working when I use addEventListener
Date 2013-09-26 12:08 +0200
Organization A noiseless patient Spider
Message-ID <l2112k$cqv$1@dont-email.me> (permalink)

Show all headers | View raw


Hello!

This works when I click the reset button in the form the confirm dialog in 
showReset is displayed.
If I click OK the fields in the form is cleared and if I click cancel the 
fields is not cleared. So far so good.
<body>
      <form id = "myForm" action = "#">
      ...
            <input id="reset" type="reset" value="Reset" onclick="return 
showReset();"/>
      </form>
</body>

<script type="text/javascript">
          function showReset(e)
          {
              return confirm("Do you really want to reset the form?");
          }
</script>

But this doesn't work. When I click the reset button in the form the 
anonymous function is called returning true if I click OK or false if I 
click cancel.
The only difference is that in the one that is working I have in the onclick 
attribute ="return showReset();"
So even if I click cancel the fields is cleared in this not working version
So what do I have to add to make this verion working ?

<body>
      <form id = "myForm" action = "#">
      ...
            <input id = "reset" type = "reset">
      </form>
</body>

<script type="text/javascript">
   myForm.addEventListener( "reset",
      function()
      {
         return confirm( "Are you sure you want to reset?" );
      },
      false );
</script>

//Tony 

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Reset not working when I use addEventListener "Tony Johansson" <johansson.andersson@telia.com> - 2013-09-26 12:08 +0200
  Re: Reset not working when I use addEventListener "Tony Johansson" <johansson.andersson@telia.com> - 2013-09-26 12:17 +0200
    Re: Reset not working when I use addEventListener "Tony Johansson" <johansson.andersson@telia.com> - 2013-09-26 12:34 +0200
  Re: Reset not working when I use addEventListener "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-09-26 12:39 +0200
  Re: Reset not working when I use addEventListener Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-26 20:47 +0200

csiph-web