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


Groups > comp.lang.javascript > #21436

Re: Reset not working when I use addEventListener

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

Show all headers | View raw


I found the reason I must change false to true in this event handler.
myForm.addEventListener( "reset",
>>      function()
>>      {
>>         return confirm( "Are you sure you want to reset?" );
>>      },
>>      false );

//tony

"Tony Johansson" <johansson.andersson@telia.com> skrev i meddelandet 
news:l211jv$fem$1@dont-email.me...
> This statement var myForm = document.getElementById( "myForm" );
> is not added in the passed code but I have it in the running code.
> I mentioned this so you don't think I have missed it.
>
> "Tony Johansson" <johansson.andersson@telia.com> skrev i meddelandet 
> news:l2112k$cqv$1@dont-email.me...
>> 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 — Previous in thread | 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