user3803457
user3803457

Reputation: 23

function not calling or firing

I checked the debugger on chrome and I couldn't spot any errors.

I have combined all my functions into one in order to make the call easier to read.

   
function runAll() {
    var validation = true;
    checkForLastName();
    checkForSelection();
    validateRadio();
    validateZipCode();
    validateEmail();
    validatePassword();
    return validation;
}
<form onSubmit ="return runAll();">
    Please enter your name.
    <input type ="text" id="lastNameField">
    <br>
    <button>submit</button>
</form>

The individual functions are firing, but together they're not.

Any thoughts?

Upvotes: 2

Views: 42

Answers (2)

ibrahim mahrir
ibrahim mahrir

Reputation: 31682

I assume that each of the functions checkForLastName, checkForSelection ... return either true or false depending on their validation of the input their handling. So what you need is to check if one of them returns false to stop the submit. If my assumption is right use this:

function runAll() {
    // if not checkForLastName return false
    if(!checkForLastName()) return false;
    // if not ...
    if(!checkForSelection()) return false;
    if(!validateRadio()) return false;
    if(!validateZipCode()) return false;
    if(!validateEmail()) return false;
    if(!validatePassword()) return false;

    // then if all is good (none of them returned false), you can return true to submit
    return true;
}

Upvotes: 1

powersof10b
powersof10b

Reputation: 31

I'm thinking the return command is causing the problem; it is only valid within a function call

<form onSubmit ="return runAll();">

should be

<form onSubmit ="runAll()">

Upvotes: 1

Related Questions