Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give confirm dialog onsubmit of a form element using javascript function [closed]

Tags:

javascript

Html code:

<form action='save.php' method="post" onsubmit="return validate(this)">
  some inputs here...
</form>

here validations are working fine. but not the confirm code. Javascript code:

function validate(theForm)
{
    validations here for input fields....
    /*confirm dialog*/
    var sure = confirm("Are you sure to proceed ?");
    if(sure == false)
    {
        return false;
    }
    else
    {
        return sure;
    }
}

confirm displays dialog but onclick of 'ok' button it is not submitting the form is there any way to submit form on confirm dialog using javascript function. Thanks in advance.

like image 228
NiksD Avatar asked Nov 01 '22 08:11

NiksD


1 Answers

As requested, answer-ing my comment:

Write your form validation function as:

function validate(theForm){
    //validation stuff here
    return confirm('Are you sure you want to proceed?');
}
like image 82
tewathia Avatar answered Nov 08 '22 11:11

tewathia