www.devguides.com | The developers choice   

 
Technologies available 
    Apache (1)
    ASP (0)
    ASP.NET (0)
    C&C++ (1)
    Google (1)
    HTML (1)
    Java (0)
    JavaScript (1)
    PERL (0)
    PHP (3)
    Unix (0)
    Visual Basic (0)
    XML (0)

Databases 
    MySQL (0)
    Oracle (0)
    PostgreSQL (0)
    SQL Server (1)

Security against 
    Backdoors (0)
    Malicious Mobile Code (0)
    Trojan Horses (0)
    Viruses (0)
    Vulnerabilities (0)

 
 You are currently reading

Forms Validation using JavaScript for your website Part 1.
posted by Andres @ 01:11 PM | Saturday, May 22, 2004
This articles covers how to validate your forms before submiting a form. You'll learn how to validate values from texboxes, checkboxes, radio buttons, and more.


 The article requested:
Before you learn about forms validations.
In this article you'll be more than satisfied about validating your own forms. I was going to write this article based on Object Oriented Programming for JavaScript but the problem is that many visitors don't know how to program for OOP, thus, I'll also publish another article based on OOP, so you can check the advantages of working with objects.

First of all, some web developers/designers tend to create small unprotected web forms/applications giving both normal/experienced users to do practically whatever they would like with our website. That is why we must do whatever we can in order to restrict users when it comes to filling the blanks of our forms. Although creating scripts for forms isn't the best thing for protection (because users can turn off JavaScript with their Web Browser), the best thing to do is to create validation functions in client-side and server-side scripting. As you undoubtly know, JavaScript is client-side technology. Now let's see a HTML form.

1  <html>
2      <head>
3          <title>
4               Registration Form
5          </title>
6      </head>
7
8      <body bgcolor="#ffffff">
9          <form method="post" action="handler.cgi" name="regform">
10            Username:<input type="text" name="username" value=""><BR>
11            Password:<input type="password" name="password" value=""><BR>
12            <input type="submit" name="submit" value="Register!"><BR>
13         </form>
14     </body>
15 </html>

I asume that you are familiar with HTML, if you don't, you shouldn't be here in the first place. As you can see from the code above, the output will be:


Most of you might do this in order to register visitors for anything that relates the involvement of them and your webpage such as forums, newsletters, etc. The important thing here is to make sure that your users complete all the required fields. This example is short but can be applied in web forms having email fields, zip code fields among other types of fields.
[1][2][3][4][Javascript here we go]


Copyright ©2004 Andrab, Inc. All rights reserved.