How to call jquery validation function outside of form

So, I have a validation script that I did some time ago. I can pass the script "this" as the form identifier to get it in the correct element (using (this)). But what if I want to call this validation function from a place other than the form itself, say in another request that wants to know if the form is valid?

   function validate_form(thisform) {
        with (thisform) {
            validate_fullName(fullName);
            validate_email(email);
            if (isName&&isEmail) {return true;};
            return false;
        };
    };

So basically I want to call this function in another function to check if the form is valid or not:

if(validate_form(WHATDOIPUTHERE?)){ // STUFF; };

Thank you very much!

+3
source share
2 answers

you can use document.getElementById("formId")(or $("#formId")in jquery):

if(validate_form(document.getElementById("formId"))){ // STUFF; };

, :

<form id="formId" method="post" action="...">

</form>
+2

- id:

function validate_form('formid') {
    with ('formid') {
        validate_fullName(fullName);
        validate_email(email);
        if (isName&&isEmail) {return true;};
        return false;
    };
};


if(validate_form('formid')){ // STUFF; };
+1

Source: https://habr.com/ru/post/1734819/


All Articles