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;
}
};
当点击submit
按钮时,我想要出现一个确认对话框,允许他们确认或取消。无论出于何种原因,确认不会在上面的代码中触发,并且表单处理就好像它不存在一样。
答案 0 :(得分:1)
您使用的是错误的表单名称:
document.addStudentForm
应为document.registerAppointment