onsubmit multiple javascript functions

后端 未结 7 565
你的背包
你的背包 2020-11-30 08:31

Does anyone know how to onsubmit multiple functions? What I intented to do was: onsubmit checks if all these functions return true, if all of them return true, then I do the

相关标签:
7条回答
  • 2020-11-30 09:02

    Following method check first validateName() function and it will process to check next function if only first function is true, also to fire third function need to return true of first & second function. So just imagine if all function are invalid & even you have different error message, you will see only error message of first function. Once validateName() function pass, you may see the error message of validatePhone() ect.

    <form id="myForm" name="myForm" action="checked.html" method="post"
    onsubmit="return (validateName() && validatePhone() && validateAddress() &&
    validateEmail() )">
    

    You can't use above if you going to show error messages according to above all validations on first submit & you can use following method if you want to fire all function (or display all validation errors) on submit.

    <form id="myForm" name="myForm" action="checked.html" method="post"
    onsubmit=" if( ( validateName() && validatePhone() && validateAddress() &&
    validateEmail() ) == false) { return false; } ">
    
    0 讨论(0)
提交回复
热议问题