Question

HTML:

<form name="registerAppointment" method="post" action="formValidations/deleteValidate.php" onSubmit="return verifyForm()">
    <input type="hidden" name="userEmail" value="<?=$_SESSION['Mail']?>" />
    <input type="text" required name="studentId" size="20"/>
    <div class="pageFormResetSubmit">
        <input type="reset" value="Reset" />
        <input type="submit" value="Submit" />
    </div>
</form>

Javascript:

    function verifyForm() {
    if (document.addStudentForm.elements["studentId"].value.length == 9) {
        if (isNaN(document.addStudentForm.elements["studentId"].value)) {
            alert("Please enter only numbers for ID - no dashes or letters.");
            return false;
        }else{
            if( window.confirm("Are you sure you want to delete this student? This action CANNOT BE UNDONE.") ){
                studentIdField.setAttribute("value", document.addStudentForm.elements["studentId"].value);
                userForm.appendChild(studentIdField);
                document.body.appendChild(userForm);
                userForm.submit();
            }
        }
    } 
    else{
        alert("The ID must be 9 characters.");
        return false;
    }
};

When the submit button is hit, I want a confirmation dialog to appear, allowing them to confirm or cancel. For whatever reason, the confirm is not firing in the above code and the form processes as if it wasn't there.

Was it helpful?

Solution

You are using wrong form name:

document.addStudentForm should be document.registerAppointment

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top