Shile
Shile

Reputation: 1063

FireEvent after e.stop()

i have a form that i stop from submitting and when confirm message pops up and user clicks yes i want when that happens to submit the form,how can i do that?i tried using fireEvent like this but it wont work...in firebug it says e is undefined.

window.addEvent('domready', function(){

var form=document.adminForm;
form.addEvent('submit', function(e){

var result=confirm("Are you sure!?");
e.stop();
if(result){
form.fireEvent("submit");  
}


});

});

Upvotes: 1

Views: 407

Answers (2)

Dimitar Christoff
Dimitar Christoff

Reputation: 26165

you need to stop the event before the confirm and submit after. http://jsfiddle.net/dimitar/qAx6H/

var form=document.id('adminForm');

form.addEvent('submit', function(e){
    e && e.stop();

    if (confirm('Are you sure?')){
        this.submit();
    }
});

Upvotes: 1

Lemur
Lemur

Reputation: 2665

As far as I understand from your question you want simple confirmation befor submittiong the form. If so, you can use this tiny script:

<input type="submit" OnClick="return confirm('Are you sure!?');" ... />

It will pop-up modal with Ok/Cancel buttons, but works fine for me.

Upvotes: 0

Related Questions