开发者

Fire javascript function after all xval validations in MVC

开发者 https://www.devze.com 2022-12-14 02:56 出处:网络
I wa开发者_Python百科nt to fire a JavaScript function when the user clicks on a button. This JavaScript should fire only after the page does the xval validation.

I wa开发者_Python百科nt to fire a JavaScript function when the user clicks on a button.

This JavaScript should fire only after the page does the xval validation.

How can this be achieved?


Do you want it to run only if the form is valid or it doesn't matter? If you want to run it only if the form is valid try this...

<form method="post" id="formToValidateID" >
    <input type="button" onclick="ButtonClicked();" />    
</form>    

<script type="text/javascript">
    function ButtonClicked() {
        if($("#formToValidateID").validate.form(){
           ExecuteJavascriptMethodIfValid();
        }
     }

    function ExecuteJavascriptMethodIfValid() {
        /* awesome code */
     }
</script>

If you don't care if the form is valid, you can leave off the if condition.

0

精彩评论

暂无评论...
验证码 换一张
取 消