Javascript asp tutorial Lesson 5-Integration

Source: Internet
Author: User

Two lines of defense, one function:
How can you ensure that the client and server have the same functions? Verification of form fields flash into our eyes. It is not difficult for someone to copy your html to another script and then change the form field verification on the client side. The solution is to place the form field verification on the server side. However, this means that a string of error messages must be returned to the server due to a small user error. So why don't we have both? In addition, we can also use the same javascript function on the client and server to ensure full consistency between the two.
Take a look at the following section. Pay special attention to the checkMyZip () function. Copy codeThe Code is as follows: <% @ LANGUAGE = "JavaScript" %>
<%
// No ASP Here, just a regular HTML Page
%>
<HTML>
<Script language = "JavaScript">
<! -- Hide
Function checkMyZip (zipCode)
{
Var myRegularExpression =/(^ \ d {5} $) | (^ \ d {5}-\ d {4} $ )/
If (myRegularExpression. test (zipCode) = true)
{
Return nothingIsWrong ();
}
Else
{
Return somethingIsWrong ();
}
}

Function nothingIsWrong ()
{
// Do nothing
Return true
}

Function somethingIsWrong ()
{
Alert ("Something is wrong with the zip code you provided .")
Document.zipCodeForm.zip CodeText. focus ()
Return false;
}
// Stop Hiding -->
</SCRIPT>
<STRONG> Type a valid U. S. Postal zip code into the box, and submit it. </STRONG>
<Form name = "zipCodeForm" ACTION = "script05a. asp" METHOD = "Post"
OnSubmit = "return checkMyZip(document.zipCodeForm.zip CodeText. value)">
<Input type = "Text" NAME = "zipCodeText"> <BR>
<BR>
<Input type = "Submit" VALUE = "Submit">
</FORM>
</HTML>

What we see in this lesson is the biggest reward for writing asp scripts with javascript. Check the script below and pay attention to the checkMyZip () function again.Copy codeThe Code is as follows: <% @ LANGUAGE = "JavaScript" %>
<%
Function checkMyZip (zipCode)
{
Var myRegularExpression =/(^ \ d {5} $) | (^ \ d {5}-\ d {4} $ )/
If (myRegularExpression. test (zipCode) = true)
{
Return nothingIsWrong ();
}
Else
{
Return somethingIsWrong ();
}
}

Function nothingIsWrong ()
{
// Do nothing
Return true
}

Function somethingIsWrong ()
{
Return false;
}

Var zipCode = new String (Request. Form ("zipCodeText "))

If (checkMyZip (zipCode) = true)
{
Response. Write ("<HTML> \ r ")
Response. Write ("The zip code you provided ...")
Response. Write ("<font color = \" RED \ "> ")
Response. Write (zipCode + "</FONT> is good. \ r ")
Response. Write ("</HTML> \ r ")
}
Else
{
Response. Write ("<HTML> \ r ")
Response. Write ("The zip code you provided ...")
Response. Write ("<font color = \" RED \ "> ")
Response. Write (zipCode + "</FONT> has a problem. \ r ")
Response. Write ("</HTML> \ r ")
}

%>

This is not the perfect column, but it contains the points we want to teach. The functions of the client and server are exactly the same. The supported functions are the same, but the changes are obvious. It's just a joke. Let's take a look at the script below. It does not have client authentication.Copy codeThe Code is as follows: <% @ LANGUAGE = "JavaScript" %>
<%
// No ASP Here, just a regular HTML Page
%>
<HTML>
<STRONG> Type a zip code (with no client side validation)
Into the box submit it. </STRONG>
<Form name = "zipCodeForm" ACTION = "script05a. asp" METHOD = "Post">
<Input type = "Text" NAME = "zipCodeText"> <BR>
<BR>
<Input type = "Submit" VALUE = "Submit">
</FORM>
</HTML>

Section 1:
This is the first section of this course plan. Some friends who have used vbscript to write asp do not need to have further research on this site. They can now use their client script usage skills to convert any function (subroutine), any page, or any application to javascript.
Other friends need to stay and continue our journey in Part 2.

Original article and example address: http://aspjavascript.com/lesson05.asp
Author: James Clark

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.