record.jsp
1<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>2<%@ taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%>3<%4String Path =Request.getcontextpath ();5String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";6%>7 8<! DOCTYPE html>9Ten One<base href= "<%=basePath%>" > A<meta http-equiv= "Pragma" content= "No-cache" > -<meta http-equiv= "Cache-control" content= "No-cache" > -<meta http-equiv= "Expires" content= "0" > the<title> Records </title> -<script src= "Http://libs.baidu.com/jquery/1.11.1/jquery.min.js" ></script> -<style> - textarea{width:400px;height:150px;} + . single{width:400px;} -.Double{width:170px;} +span{font-weigh:bold;color:red;} A</style> at<script> - functionchecknull (Element) - { - varError = $ ("#error"); - varEle =$ (element); -Error.html (""); in if(Ele.val () = = "") - { toError.html (ele.attr ("info") + "cannot be empty!"); + return false; - } the return true; * } $ functionchecktime ()Panax Notoginseng { - varBilltime = $ ("#billtime"); the varTime =billtime.val (); + varRegtime =/^ (\d{4})-(0\d{1}|1[0-2])-(0\d{1}|[ 12]\D{1}|3[01]) $/; A varError = $ ("#error"); theError.html (""); + if(Regtime.test (time)) - { $ return true; $ } -error.html ("date format is incorrect!" ( YYYY-MM-DD) "); - return false; the } - functionChecktype ()Wuyi { the varRadios = $ ("input[type= ' Radio ')"); - varError = $ ("#error"); WuError.html (""); - for(vari = 0; i < radios.length; i++) About { $ if(radios[i].checked = =true) - { - return true; - } A } +error.html ("Please select a record type!")); the return false; - } $ functionCheckall () the { the if(Checknull ($ ("#title") [0]) && checknull ($ ("#price") [0]) the&& Checknull ($ ("#remark") [0])) the { - if(Checktime () &&Checktype ()) in { the return true; the } About } the return false; the } the $( + functionLoadtype () - { the varTypediv = $ ("#typeDiv");BayiTypediv.html ("Type:"); the $.ajax the ({ -URL: "Type_query", -Type: "POST", theDataType: "JSON", theSuccessfunction(data) the { the varTypes =data.list; - for(vari = 0; i < types.length; i++) the { the varRadio = "<input type= ' Radio ' name= ' typeid ' value= '" +types[i].id+ "'/> ' +Types[i].name; the typediv.append (radio);94 } the }, theErrorfunction() the {98Alert ("Server Busy! "); About } - });101 }102 );103</script>104 the 106<body>107<div align= "center" >108109<form action= "Bill_insert" method= "POST" onsubmit= "return Checkall ();" > the<div id= "Typediv" ></div><br/>111Title: <input type= "text" name= "title" id= "title" info= "title" class= "single" onblur= "Checknull (this);" Maxlength= "25"/ ><br/><br/> theDate: <input type= "text" name= "Billtime" id= "Billtime" info= "date" class= "Double" Onblur= "Checktime ();"/>113Amount: <input type= "text" name= "price" id= "price" info= "Amount" class= "Double" onblur= "checknull (this);" /><br/><br/> theDescription: <textarea name= "Remark" info= "description" id= "remark" maxlength= "" onblur= "checknull (this);" /></textarea><br/><br/> the<input type= "reset" value= "reset"/> the<input type= "Submit" value= "Save"/> 117<input type= "button" value= "return" onclick= "javascript:window.location= ' index.jsp '"/>118</form>119<c:iftest= "${result = = ' success '}" > -<script>alert ("Saved successfully!"); </script>121</c:if>122<c:iftest= "${result = = ' failed '}" >123<script>alert ("Server Busy!"); </script>124</c:if> the<span>126</div>127</body> -
jquery form Validation