简体   繁体   中英

How to validate a specific form (JavaScript)

I realize my title may seem general but I have a specific problem I can't find the answer to. I made a form where people input information and I actively check their info to see if it is formatted correctly. If not an alert message pops up. So far I have three functions in my check. Calling example:

<input type="text" name="LastName" onblur="javascript:validateName(this.value);" required>  

So I call each one individually in the html. Now what I would like to do is have a fourth function that turn the submit button on or off depending on the outcomes of the other functions. But, I do not know how to put in the parameters for the other functions because they currently use this.value . If it is unclear still I want

function validate submit(...) {
     if (validateName() == true && validatePhone() == true && validateEmail() == true){
          document.getElementById("btnformsubmission").disabled = false;                 
     } 

Thanks in advance!

根据您的问题,我会说您需要一个isValid标志,该标志在您的各个验证功能和Submit函数之外设置,如果该标志为true,则可以允许您在Submit函数中进行提交。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM