Responding to form submission events with JavaScript

Source: Internet
Author: User
Tags empty reset
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>
&LT;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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.