JavaScript has a very powerful function, which is validating what you input in the forms of the website on the client side. Although PHP and other script languages can do the same thing, the benefits of utilizing JavaScript to do this work are: firstly, the response speed is much faster than the server-side languages. Even though there is a crash on the server, the browser can validate the codes in stead of waiting for the feedback from the server. In this way, it improves the website efficiency very much.
The second advantage is JavaScript codes on validation is quite simple whist some other languages have quite complex syntax. Sometimes, there are only a few lines of codes in JavaScript could do the check work rather than hundreds of lines codes in other languages.
Often, the codes to do the validation task are like below:
function noblanks()
{
if (document.demoform.demofield.value=="")
{
alert ("Field is blank!");
return false;
}
return true;
}
The codes are just a very simple example to check whether there is a blank in a column of the form area. Sometimes, combined with regular expressions, we could validate any data in any format in order to make the input content match our expectations.
没有评论:
发表评论