Required Form Validation

Posted: November 5, 2007 in JavaScript Stuffs
Tags: ,

Heading

Required Form Field Validation

Description

JavaScript “Required Form Field Validation” ;

Preview

form-validation.jpg

Code

<html>

<head>

<script language=’JavaScript’
type=’text/JavaScript’>

//Made by 1st JavaScript
Editor

//http://www.yaldex.com

function fifteenth(sixteenth)

{

var seventeenth =
Array(“FirstName”, “LastName”);

var eighteenth =
Array(“First Name”, “Last Name”);

var nineteenth = “Please
complete these fields:\n”;

var twentieth =
nineteenth.length;

for (var first2 = 0; first2
< seventeenth.length;

first2++)

{

var second2 =
sixteenth.elements[seventeenth[first2]];

if (second2)

{

switch(second2.type)

{

case “select-one”:

if
(second2.selectedIndex == -1 || second2.options[second2.selectedIndex].text ==
“”)

{

nineteenth
+= ” – ” + eighteenth[first2] + “\n”;

}

break;

case
“select-multiple”:

if
(second2.selectedIndex == -1)

{

nineteenth
+= ” – ” + eighteenth[first2] + “\n”;

}

break;

case “text”:

case “textarea”:

if
(second2.value == “” || second2.value == null)

{

nineteenth
+= ” – ” + eighteenth[first2] + “\n”;

}

break;

default:

}

if (second2.type ==
undefined)

{

var third2 =
false;

for (var fourth2 =
0; fourth2 < second2.length;

fourth2++)

{

if
(second2[fourth2].checked)

{

third2 =
true;

}

}

if (!third2)

{

nineteenth += ”
– ” + eighteenth[first2] + “\n”;

}

}

}

}

if (nineteenth.length ==
twentieth)

{

return true;

}

else

{

alert(nineteenth);

return false;

}

}

</script>

<title></title>

</head>

<body>

<form name=”formcheck”
onsubmit=”return fifteenth(this);”>

Your First Name:

<input type=text name=”FirstName”
size=”28″><br>

Your Last Name:

<input type=text name=”LastName”
size=”28″><br>

<input type=submit
value=”Submit Form”><br>

</form>

</body>

</html>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s