JavaScript code to stop form submission

前端 未结 12 2097
感情败类
感情败类 2020-11-21 06:40

One way to stop form submission is to return false from your JavaScript function.

When the submit button is clicked, a validation function is called. I have a case i

12条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-21 07:01

    Just use a simple button instead of a submit button. And call a JavaScript function to handle form submit:

    
    

    Function within a script tag:

    function submit_form() {
        if (conditions) {
            document.forms['myform'].submit();
        }
        else {
            returnToPreviousPage();
        }
    }
    

    You can also try window.history.forward(-1);

提交回复
热议问题