Javascript| response we sometimes want to submit the form before the user input data validation, if the input is not correct, give a hint, and let the new input, then how do we achieve it?
Now I'm going to give a brief description of the implementation of a requirement:
My Functional Requirements:
The user enters a type that requires a number, so we do a digital validation.
When submitting the type ID field is null validation, if it is empty, give a hint, and ask the new input
Our JSP code is as follows:
<% @page contenttype= "text/html; CHARSET=GBK "%>
<title>addNewsType</title>
<body bgcolor= "#ffffff" >
<form name= "Form1" method= "Post" action= "<%=request.getcontextpath ()%>/news/newstypeaddaction.sh"
>
<table>
<tr>
<td> News Type Number </td>
<td>
<input type= "text" name= "typeID" onblur= "IsDigit (this.value)" > </td>
</tr>
<tr>
<td> News type name </td>
<td>
<input type= "text" Name= "TypeName" > </td>
</tr>
<tr>
<td> News Store Directory name </td>
<td>
<input type= "text" name= "dir" > </td>
</tr>
<tr>
<td> Use template name </td>
<td>
<input type= "text" name= "templatename" > </td>
</tr>
<tr>
<TD colspan= "2" >
<div align= "center" >
<input type= "Submit" name= "submit" value= "Submit" >
<input type= "reset" value= "reset" >
</div></td>
</tr>
</table>
</form>
<script type= "Text/javascript" >
function IsDigit (s)
{
var patrn=/^[0-9]{1,20}$/;
if (!patrn.exec (s) &&s!= "") {
Alert ("Please enter a number!");
Document.form1.typeid.value= "";
Document.form1.typeid.focus ();
return false;
}
}
function ACTIONCheck () {
if (document.form1.typeid.value== "") {
Alert ("News type number cannot be empty!");
Document.form1.typeid.value= "";
Document.form1.typeid.focus ();
return false;
}
}
</script>
</body>
Our JavaScript validation section does not need to be explained, primarily because our inspection code is implemented in the OnSubmit event of form, and returns values are used to return the value. That is, the part that the underline shows.
Own a little superficial understanding, hope more advice.