我编写了以下函数来检查start_date字段是否为空,并在单击提交按钮时显示正确的消息.但随后它将控制权转移到上一页.因此,用户必须再次写入该表单上的所有其他字段.即使在提示错误消息后,有没有办法留在该页面上,其他所有字段都是值.
//JavaScript
function checkform() {
if(document.frmMr.start_date.value == "") {
alert("please enter start_date");
return false;
} else {
document.frmMr.submit();
}
}
// HTML
<html>
<form name=frmMr action="page1.jsp">
Enter Start date:
<input type="text" size="15" name="start_date" id="start_date">
<input type="submit" name="continue" value="submit" onClick="checkform();">
</form>
</html>
Run Code Online (Sandbox Code Playgroud)
提前致谢