SlideShare ist ein Scribd-Unternehmen logo
1 von 6
Lecture 17
You will learn in this Lecture

FormValidation
     - Text Box validation
     - Check Box validation
     - Password validation
     - select list box validation

Before starting with this lecture, There are few questions that deserve to be
answered, What is validation and Why is it requried? Let me answer the first
question and then we will move on to the second question.

So, the first question is, What is validation?
Validation test for required strings contain a specific value, a range of accepted
value or a pattern of acceptable format. For example, If you make a form, and
ask the user to enter name, email address, and comment. If he leaves every field
blank, and click Enter. You will not get any information.
This means we are validating (checking) the values entered by the user, if he has
entered some value or not, if not, then ask him to enter the value and if he has
entered wrong value,then ask him to enter the correct value.

I hope you must have got the answer, why validation is required.

Next question is How validation is done, just read the following lines.

So, as soon as the user clicks Enter, There are two possibilites

1. Send the data that use has entered to the server, and check the values, if
there are any, if there are no values entered by him or if wrong values are
entered by him, ask him to enter the value, and move back to the same form.

2. Or, before sending the data to the server, check whether user has entered any
value or not. If he has entered the value, then the value is corrent or not.

Second method is what we will follow, and is called as client side scripting,
whereas the first method is called as Serve side scripting. JavaScript is popular
for client side scripting and ASP, JSP, PHP are popular for server side scripting.
It is high time to understand the difference between Client Side Scripting and
Server Side Scripting.

When we use a scripting language, that works on the server side, it is called as
Server Side Scripting language,
If we use a scripting language, that works on client side (i.e. browser), it is called
as Client Side Scripting language.
So, Now let us start with validating user input.

When we make a form, we ask the user to enter username, password, and may
ask him to fill up some check boxes, radio butons, and also ask him to write
some comments. It is compulsay for the user to enter username, and password,
but it is not compulsay for him to give his comments. So the things that are
compulsary, cannot be left blank. This is one of the validation, forcing the user
not to leave a field blank.

Let me list down some of the common validations needed
- Password Validation
- Text Field not blank (Name)

Below is the code for Text Box validation
<html>
<head>
      <script language="JavaScript">

       function validate()
       {
       firstName=document.myForm.fname.value;
       lastName=document.myForm.fname.value;
       if(firstName=="")
                window.alert("Name Field cannot be left blank");
       if(lastName=="")
                window.alert("Name Field cannot be left blank");
       switch (firstName.charAt(0))
       {
                case "0":
                case "1":
                case "2":
                case "3":
                case "4":
                case "5":
                case "6":
                case "7":
                case "8":
                case "9": window.alert("First chaaracter cannot be a number");
       }
       }

      </script>
</head>
      <body>
      <form name="myForm">
<input type="text" name="fname"> <br>
            <input type="text" name="lname"> <br>
            <input type="submit" onClick="validate()"> <br>
      </form>
      </body>
</html>

And, Now we have the code for Password Validation
<html>
<head>
      <script language="JavaScript">

      function validate()
      {
      passwd=document.myForm.pass;
      cpasswd=document.myForm.cpass;
      if (passwd=="")
              window.alert("Password field cannot be blank");
      if (cpasswd=="")
              window.alert("Confirm Password field cannot be blank");

      if (passwd!=cpasswd)
              window.alert("Passwords dont match");
      }

      </script>
</head>
      <body>
      <form name="myForm">
             Password<input type="password" name="pass"> <br>
             Confirm password<input type="password" name="cpass"> <br>
             <input type="submit" onClick="validate()"> <br>
      </form>
      </body>
</html>

Validate Selection List

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function validateForm(objForm)
{
       var returnStatus = 1;
if (objForm.Make.selectedIndex == 0) {
      alert("Please select a car make");
      returnStatus = 0;
      }
      else
      alert("You selected" +
objForm.Make.options[objForm.Make.selectedIndex].text + objForm.Make.value);

      if (returnStatus) {
      objForm.submit();
      }
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<FORM ACTION="test.asp" NAME="testform">
<SELECT NAME="Make">
       <OPTION VALUE="0" SELECTED>Select One</OPTION>
       <OPTION VALUE="1">Ford</OPTION>
       <OPTION VALUE="2">Chevy</OPTION>
       <OPTION VALUE="3">Pontiac</OPTION>
       <OPTION VALUE="4">Dodge</OPTION>
</SELECT>
<INPUT TYPE="BUTTON" VALUE="Send form"
onClick="validateForm(document.testform)">
</FORM>
</BODY>
</HTML>

Dynamically Populating a Selectin List

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function populate(objForm)
{


      if (objForm.Make.selectedIndex == 0)
      {
      alert("Please select a car make");
      }
      else
      {
alert("You selected" +
objForm.Make.options[objForm.Make.selectedIndex].text + objForm.Make.value);
      if (objForm.Make.selectedIndex == 1)
      {
              objForm.Type.length=2;
              objForm.Type.options[0].text="d1";
              objForm.Type.options[0].value="1";

            objForm.Type.options[1].text="d2";
            objForm.Type.options[1].value="2";
      }

      if (objForm.Make.selectedIndex == 2)
      {
              objForm.Type.length=2;
              objForm.Type.options[0].text="h1";
              objForm.Type.options[0].value="1";

            objForm.Type.options[1].text="h2";
            objForm.Type.options[1].value="2";
      }

      if (objForm.Make.selectedIndex == 3)
      {
              objForm.Type.length=3;
              objForm.Type.options[0].text="m1";
              objForm.Type.options[0].value="1";

            objForm.Type.options[1].text="m2";
            objForm.Type.options[1].value="2";

            objForm.Type.options[2].text="m3";
            objForm.Type.options[2].value="3";
      }

      if (objForm.Make.selectedIndex == 4)
      {
              objForm.Type.length=4;
              objForm.Type.options[0].text="v1";
              objForm.Type.options[0].value="1";

            objForm.Type.options[1].text="v2";
            objForm.Type.options[1].value="2";

            objForm.Type.options[2].text="v3";
            objForm.Type.options[2].value="3";
objForm.Type.options[3].text="v4";
            objForm.Type.options[3].value="4";
      }



      }



}
// -->
</SCRIPT>
</HEAD>
<BODY>
<FORM ACTION="test.asp" NAME="testform">
<SELECT NAME="Make" onChange="populate(document.testform)">
       <OPTION VALUE="0" SELECTED>Select One</OPTION>
       <OPTION VALUE="1">Daewoo</OPTION>
       <OPTION VALUE="2">Hyundae</OPTION>
       <OPTION VALUE="3">Mercedes</OPTION>
       <OPTION VALUE="4">Volswagen</OPTION>
</SELECT>

<SELECT NAME="Type">
</SELECT>
<INPUT TYPE="BUTTON" VALUE="Send form"
onClick="validateForm(document.testform)">
</FORM>
</BODY>
</HTML>

Validating a Check Box

Weitere ähnliche Inhalte

Was ist angesagt?

05 html-forms
05 html-forms05 html-forms
05 html-forms
Palakshya
 

Was ist angesagt? (20)

Form validation server side
Form validation server side Form validation server side
Form validation server side
 
28,29. procedures subprocedure,type checking functions in VBScript
28,29. procedures  subprocedure,type checking functions in VBScript28,29. procedures  subprocedure,type checking functions in VBScript
28,29. procedures subprocedure,type checking functions in VBScript
 
Java scriptfunction
Java scriptfunctionJava scriptfunction
Java scriptfunction
 
30,31,32,33. decision and loop statements in vbscript
30,31,32,33. decision and loop statements in vbscript30,31,32,33. decision and loop statements in vbscript
30,31,32,33. decision and loop statements in vbscript
 
Java script -23jan2015
Java script -23jan2015Java script -23jan2015
Java script -23jan2015
 
Java Script
Java ScriptJava Script
Java Script
 
Html JavaScript and CSS
Html JavaScript and CSSHtml JavaScript and CSS
Html JavaScript and CSS
 
Java script
Java scriptJava script
Java script
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Produce Cleaner Code with Aspect-Oriented Programming
Produce Cleaner Code with Aspect-Oriented ProgrammingProduce Cleaner Code with Aspect-Oriented Programming
Produce Cleaner Code with Aspect-Oriented Programming
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Java script
Java scriptJava script
Java script
 
PHP - Introduction to PHP Forms
PHP - Introduction to PHP FormsPHP - Introduction to PHP Forms
PHP - Introduction to PHP Forms
 
05 html-forms
05 html-forms05 html-forms
05 html-forms
 
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...
 
Java script basic
Java script basicJava script basic
Java script basic
 
Writing clean code
Writing clean codeWriting clean code
Writing clean code
 
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia InstituteMVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
 
Javascript
JavascriptJavascript
Javascript
 
Javascript
JavascriptJavascript
Javascript
 

Andere mochten auch (17)

Html basics 6 image
Html basics 6 imageHtml basics 6 image
Html basics 6 image
 
Java script frame history
Java script frame historyJava script frame history
Java script frame history
 
Java script objects 2
Java script objects 2Java script objects 2
Java script objects 2
 
Week5
Week5Week5
Week5
 
Lecture4 isoosi
Lecture4 isoosiLecture4 isoosi
Lecture4 isoosi
 
Lecture2 networkclassification
Lecture2 networkclassificationLecture2 networkclassification
Lecture2 networkclassification
 
Assignment4
Assignment4Assignment4
Assignment4
 
Assignment sw
Assignment swAssignment sw
Assignment sw
 
Solution2
Solution2Solution2
Solution2
 
Set
SetSet
Set
 
Lecture1 introductiontonetwork
Lecture1 introductiontonetworkLecture1 introductiontonetwork
Lecture1 introductiontonetwork
 
Html basics 3 font align
Html basics 3 font alignHtml basics 3 font align
Html basics 3 font align
 
Induction
InductionInduction
Induction
 
Html basics 10 form
Html basics 10 formHtml basics 10 form
Html basics 10 form
 
Html basics 1
Html basics 1Html basics 1
Html basics 1
 
Html basics 7 table
Html basics 7 tableHtml basics 7 table
Html basics 7 table
 
Week7
Week7Week7
Week7
 

Ähnlich wie Html basics 11 form validation

Ähnlich wie Html basics 11 form validation (20)

Chat php
Chat phpChat php
Chat php
 
Javascript
JavascriptJavascript
Javascript
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
Javascript1
Javascript1Javascript1
Javascript1
 
PHP Form Validation Technique
PHP Form Validation TechniquePHP Form Validation Technique
PHP Form Validation Technique
 
javascript.pptx
javascript.pptxjavascript.pptx
javascript.pptx
 
2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security
 
Introduction of javascript
Introduction of javascriptIntroduction of javascript
Introduction of javascript
 
Form demoinplaywithmysql
Form demoinplaywithmysqlForm demoinplaywithmysql
Form demoinplaywithmysql
 
phptut2
phptut2phptut2
phptut2
 
phptut2
phptut2phptut2
phptut2
 
phptut2
phptut2phptut2
phptut2
 
phptut2
phptut2phptut2
phptut2
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
 
full stack practical assignment msc cs.pdf
full stack practical assignment msc cs.pdffull stack practical assignment msc cs.pdf
full stack practical assignment msc cs.pdf
 
JavaScript Training
JavaScript TrainingJavaScript Training
JavaScript Training
 
Js mod1
Js mod1Js mod1
Js mod1
 
Java script
Java scriptJava script
Java script
 
JavaScript - Chapter 14 - Form Handling
 JavaScript - Chapter 14 - Form Handling   JavaScript - Chapter 14 - Form Handling
JavaScript - Chapter 14 - Form Handling
 

Mehr von H K (20)

Assignment4
Assignment4Assignment4
Assignment4
 
Assignment3
Assignment3Assignment3
Assignment3
 
Solution3
Solution3Solution3
Solution3
 
Mid-
Mid-Mid-
Mid-
 
Assignment4
Assignment4Assignment4
Assignment4
 
Dm assignment3
Dm assignment3Dm assignment3
Dm assignment3
 
Proof
ProofProof
Proof
 
Resolution
ResolutionResolution
Resolution
 
Assignment description
Assignment descriptionAssignment description
Assignment description
 
Dm assignment2
Dm assignment2Dm assignment2
Dm assignment2
 
Dm assignment1
Dm assignment1Dm assignment1
Dm assignment1
 
Logic
LogicLogic
Logic
 
Introduction
IntroductionIntroduction
Introduction
 
Assignment 2 sol
Assignment 2 solAssignment 2 sol
Assignment 2 sol
 
Assignment sw solution
Assignment sw solutionAssignment sw solution
Assignment sw solution
 
Violinphoenix
ViolinphoenixViolinphoenix
Violinphoenix
 
Ie project
Ie projectIe project
Ie project
 
Assignment cn subnetting
Assignment cn subnettingAssignment cn subnetting
Assignment cn subnetting
 
Assignment uplaodfile
Assignment uplaodfileAssignment uplaodfile
Assignment uplaodfile
 
Assignment sw
Assignment swAssignment sw
Assignment sw
 

Kürzlich hochgeladen

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Kürzlich hochgeladen (20)

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 

Html basics 11 form validation

  • 1. Lecture 17 You will learn in this Lecture FormValidation - Text Box validation - Check Box validation - Password validation - select list box validation Before starting with this lecture, There are few questions that deserve to be answered, What is validation and Why is it requried? Let me answer the first question and then we will move on to the second question. So, the first question is, What is validation? Validation test for required strings contain a specific value, a range of accepted value or a pattern of acceptable format. For example, If you make a form, and ask the user to enter name, email address, and comment. If he leaves every field blank, and click Enter. You will not get any information. This means we are validating (checking) the values entered by the user, if he has entered some value or not, if not, then ask him to enter the value and if he has entered wrong value,then ask him to enter the correct value. I hope you must have got the answer, why validation is required. Next question is How validation is done, just read the following lines. So, as soon as the user clicks Enter, There are two possibilites 1. Send the data that use has entered to the server, and check the values, if there are any, if there are no values entered by him or if wrong values are entered by him, ask him to enter the value, and move back to the same form. 2. Or, before sending the data to the server, check whether user has entered any value or not. If he has entered the value, then the value is corrent or not. Second method is what we will follow, and is called as client side scripting, whereas the first method is called as Serve side scripting. JavaScript is popular for client side scripting and ASP, JSP, PHP are popular for server side scripting. It is high time to understand the difference between Client Side Scripting and Server Side Scripting. When we use a scripting language, that works on the server side, it is called as Server Side Scripting language, If we use a scripting language, that works on client side (i.e. browser), it is called as Client Side Scripting language.
  • 2. So, Now let us start with validating user input. When we make a form, we ask the user to enter username, password, and may ask him to fill up some check boxes, radio butons, and also ask him to write some comments. It is compulsay for the user to enter username, and password, but it is not compulsay for him to give his comments. So the things that are compulsary, cannot be left blank. This is one of the validation, forcing the user not to leave a field blank. Let me list down some of the common validations needed - Password Validation - Text Field not blank (Name) Below is the code for Text Box validation <html> <head> <script language="JavaScript"> function validate() { firstName=document.myForm.fname.value; lastName=document.myForm.fname.value; if(firstName=="") window.alert("Name Field cannot be left blank"); if(lastName=="") window.alert("Name Field cannot be left blank"); switch (firstName.charAt(0)) { case "0": case "1": case "2": case "3": case "4": case "5": case "6": case "7": case "8": case "9": window.alert("First chaaracter cannot be a number"); } } </script> </head> <body> <form name="myForm">
  • 3. <input type="text" name="fname"> <br> <input type="text" name="lname"> <br> <input type="submit" onClick="validate()"> <br> </form> </body> </html> And, Now we have the code for Password Validation <html> <head> <script language="JavaScript"> function validate() { passwd=document.myForm.pass; cpasswd=document.myForm.cpass; if (passwd=="") window.alert("Password field cannot be blank"); if (cpasswd=="") window.alert("Confirm Password field cannot be blank"); if (passwd!=cpasswd) window.alert("Passwords dont match"); } </script> </head> <body> <form name="myForm"> Password<input type="password" name="pass"> <br> Confirm password<input type="password" name="cpass"> <br> <input type="submit" onClick="validate()"> <br> </form> </body> </html> Validate Selection List <HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- function validateForm(objForm) { var returnStatus = 1;
  • 4. if (objForm.Make.selectedIndex == 0) { alert("Please select a car make"); returnStatus = 0; } else alert("You selected" + objForm.Make.options[objForm.Make.selectedIndex].text + objForm.Make.value); if (returnStatus) { objForm.submit(); } } // --> </SCRIPT> </HEAD> <BODY> <FORM ACTION="test.asp" NAME="testform"> <SELECT NAME="Make"> <OPTION VALUE="0" SELECTED>Select One</OPTION> <OPTION VALUE="1">Ford</OPTION> <OPTION VALUE="2">Chevy</OPTION> <OPTION VALUE="3">Pontiac</OPTION> <OPTION VALUE="4">Dodge</OPTION> </SELECT> <INPUT TYPE="BUTTON" VALUE="Send form" onClick="validateForm(document.testform)"> </FORM> </BODY> </HTML> Dynamically Populating a Selectin List <HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- function populate(objForm) { if (objForm.Make.selectedIndex == 0) { alert("Please select a car make"); } else {
  • 5. alert("You selected" + objForm.Make.options[objForm.Make.selectedIndex].text + objForm.Make.value); if (objForm.Make.selectedIndex == 1) { objForm.Type.length=2; objForm.Type.options[0].text="d1"; objForm.Type.options[0].value="1"; objForm.Type.options[1].text="d2"; objForm.Type.options[1].value="2"; } if (objForm.Make.selectedIndex == 2) { objForm.Type.length=2; objForm.Type.options[0].text="h1"; objForm.Type.options[0].value="1"; objForm.Type.options[1].text="h2"; objForm.Type.options[1].value="2"; } if (objForm.Make.selectedIndex == 3) { objForm.Type.length=3; objForm.Type.options[0].text="m1"; objForm.Type.options[0].value="1"; objForm.Type.options[1].text="m2"; objForm.Type.options[1].value="2"; objForm.Type.options[2].text="m3"; objForm.Type.options[2].value="3"; } if (objForm.Make.selectedIndex == 4) { objForm.Type.length=4; objForm.Type.options[0].text="v1"; objForm.Type.options[0].value="1"; objForm.Type.options[1].text="v2"; objForm.Type.options[1].value="2"; objForm.Type.options[2].text="v3"; objForm.Type.options[2].value="3";
  • 6. objForm.Type.options[3].text="v4"; objForm.Type.options[3].value="4"; } } } // --> </SCRIPT> </HEAD> <BODY> <FORM ACTION="test.asp" NAME="testform"> <SELECT NAME="Make" onChange="populate(document.testform)"> <OPTION VALUE="0" SELECTED>Select One</OPTION> <OPTION VALUE="1">Daewoo</OPTION> <OPTION VALUE="2">Hyundae</OPTION> <OPTION VALUE="3">Mercedes</OPTION> <OPTION VALUE="4">Volswagen</OPTION> </SELECT> <SELECT NAME="Type"> </SELECT> <INPUT TYPE="BUTTON" VALUE="Send form" onClick="validateForm(document.testform)"> </FORM> </BODY> </HTML> Validating a Check Box