1

Firefox is clearing the form when pressing "cancel" on the "reset"(s) "confirm" window. Tried that:

<input class="grow" type="reset" name="reset" id="res" onclick="confirm('reset?')">

And that:

$('#res').on('click',function(){
    var c = confirm('Reset the data?');
    if(c==true){
        $( ".counter" ).text( q  + " of " + n.length );
    }
});

Both work properly in Chrome and Safari.

GSerg
  • 76,472
  • 17
  • 159
  • 346
orlovskiy
  • 15
  • 5
  • You never cancel the default behaviour of the button, so naturally it happens. – GSerg Feb 01 '16 at 14:26
  • You bit wrong about that. I want only to confirm, not to change the natural behavior, like making it a 'submit' button for an example. – orlovskiy Feb 01 '16 at 15:19
  • The `confirm()` function is not related in any way to an ``. If you call this function from the button's `onclick`, that is not going to magically confirm or cancel the button's behaviour. You could call `alert()` or `prompt()` instead, and that would have the same effect (that is, no effect). If you want to conditionally cancel default behaviour of an HTML element, you should [do so explicitly](http://stackoverflow.com/q/1357118/11683). – GSerg Feb 01 '16 at 15:52
  • Thank you! But I'm stuck a bit with complete understanding because It works if 'return' placed before confirm. – orlovskiy Feb 01 '16 at 16:02
  • T.J. Crowder [comments](http://stackoverflow.com/questions/1357118/event-preventdefault-vs-return-false#comment10263970_1357151) why it works. – GSerg Feb 01 '16 at 18:13

1 Answers1

0

You're not doing anything with the return value. Try:

<input class="grow" type="reset" name="reset" id="res" onclick="return confirm('reset?')">

Same for the jQuery version:

$('#res').on('click',function(){
    var c = confirm('Reset the data?');
    if(c==true){
        $( ".counter" ).text( q  + " of " + n.length );
    }
    return c;
});
j08691
  • 204,283
  • 31
  • 260
  • 272
  • Thank you! I thought that 'confirm' is a utility which automatically returns a boolean value. Honestly I don't understand this completely. – orlovskiy Feb 01 '16 at 15:09