这是我的jsp页面,我现在正在进行员工管理工作,我希望在所有验证成功或真实后弹出确认消息,并且应该询问用户是或否。提交表格。
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ page session="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Employee Management System</title>
<link href="CSS/style.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/smoothness/jquery-ui.css" />
<script language="javascript" type="text/javascript">
function checkform(pform1){
var str=pform1.bloodGroup.value;
var email = pform1.email.value;
var phone = pform1.phoneNumber.value;
var cleanstr = phone.replace(/[\(\)\.\-\ ]/g, '');
var err={};
var validemail =/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
var income = pform1.annualIncome.value;
var Id = pform1.employeeId.value;
var salary = income.replace(/[\(\)\.\-\ ]/g, '');
var Eid = Id.replace(/[\(\)\.\-\ ]/g, '');
//check required fields
//password should be minimum 4 chars but not greater than 8
if (((str.length < 1) || (str.length > 3))&& (!(str.notequals("")))) {
err.message="Invalid blood group";
err.field=pform1.bloodGroup;
}
//validate email
else if( (email != "") && !(validemail.test(email))){
err.message="Invalid email";
err.field=pform1.email;
}
//check phone number
else if (isNaN((cleanstr))) {
err.message="Invalid phone number";
err.field=pform1.phoneNumber;
}
else if (isNaN((salary))) {
err.message="Invalid Annual Income";
err.field=pform1.annualIncome;
}
else if (isNaN((Eid))) {
err.message="Invalid EmployeeID";
err.field=pform1.annualIncome;
}
if(err.message)
{
document.getElementById('divError').innerHTML = err.message;
err.field.focus();
alert(err.message);
return false;
}
else
{
return true;
}
}
</script>
<script>
$(function() {
$( "#dateOfBirth" ).datepicker({
showOn: "button",
buttonImage: "Pictures/calendicon.jpg" ,
buttonImageOnly: true,
buttonText: "Select date",
/* dateFormat: 'dd/mm/yy ' */
});
});
</script>
</head>
<body><center>
<h2>Employee Management System</h2>
<form:form method="POST" action="./add.html" modelAttribute ="employee" onsubmit="return checkform(this);" >
<div id="errmsgbox">
<div id="divError"></div>
</div>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="14%">Employee ID<span class="mandatory" >*</span></td>
<td width="35%"> <form:hidden path="ID" />
<form:input path="employeeId" required = "required"/></td>
<td width="16%">Employee Name<span class="mandatory" >*</span></td>
<td width="35%"><form:input path="employeeName" required = "required" /></td>
</tr>
<tr>
<td>DOB<span class="mandatory" >*</span></td>
<td><form:input path ="dateOfBirth" required = "required" id="dateOfBirth"></form:input></td>
<style>
img.ui-datepicker-trigger {
width: 15px;
height: 15px;
}
</style>
<td>Blood group </td>
<td><form:input path="bloodGroup" /></td>
</tr>
<tr>
<td>Annual Income </td>
<td><form:input path ="annualIncome" /></td>
<td>Qualification</td>
<td><form:input path ="qualification" /></td>
</tr>
<tr>
<td>Pan No.</td>
<td><form:input path="panNumber" /></td>
<td>Phone No. </td>
<td><form:input path="phoneNumber" /></td>
</tr>
<tr>
<td>Sex</td>
<td><form:radiobutton path="sex" value="m"/>Male
<form:radiobutton path="sex" value="f"/>Female</td>
<td>Email</td>
<td><form:input path="email" /></td>
</tr>
<tr>
<td>Address</td>
<td colspan="3"><textarea name="" cols="" rows="2"></textarea></td>
</tr>
</table>
<div>
<input name="submit2" type="submit" title="Submit" value="Submit" />
<input type="button" name="reset_form" value="Reset" onclick="this.form.reset();"/>
<a href="index.html"><input name="submit3" type="button" title="Reset" value="View All"/></a>
</div>
</form:form>
</center>
</body>
</html>
答案 0 :(得分:0)
您可以在javascript中使用alert()。
答案 1 :(得分:0)
按照else block
中的代码
checkform()
if(confirm("Your question here?")) {
return true;
} else {
return false;
}