问题描述:

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");

}

});

});

网友答案:

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();
    }
});
网友答案:

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.

相关阅读:
Top