0% found this document useful (0 votes)
35 views

Java Script Validation

The document describes how to perform validation on a form using JavaScript. It defines a validate() function that checks if required fields like first name, last name, date of birth, age, password are empty and alerts the user. It also checks if a gender is selected and at least one language checkbox is checked, alerting the user if not. If all validations pass, true is returned and the form can be submitted.

Uploaded by

SAI RAM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Java Script Validation

The document describes how to perform validation on a form using JavaScript. It defines a validate() function that checks if required fields like first name, last name, date of birth, age, password are empty and alerts the user. It also checks if a gender is selected and at least one language checkbox is checked, alerting the user if not. If all validations pass, true is returned and the form can be submitted.

Uploaded by

SAI RAM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Validation using java script

<html>
<head>
<title>validity</title>

<script type="text/javascript">
<!--
function validate()
{
if(document.form1.first_name.value == "")
{
alert("Please provide your firstname!");
document.form1.first_name.focus();
return false;
}

if(document.form1.last_name.value =="")
{
alert("Please provide your lastname!");
document.form1.last_name.focus();
return false;
}

if(document.form1.dob.value =="")
{
alert("Please provide your date of birth!");
document.form1.dob.focus();
return false;
}

if(document.form1.age.value =="")
{
alert("Please provide your age");
document.form1.age.focus();
return false;
}

if(document.form1.password.value =="")
{
alert("Please provide password");
document.form1.password.focus();
return false;
}

if(document.form1.des.value =="")
{
alert("Please provide the description");
document.form1.description.focus();
return false;
}

if((document.form1.gender[0].checked == false) &&


(document.form1.gender[1].checked == false))
{
alert("Please select any of the gender");
return false;
}

var c=document.form1.lang;
for(var i=0;i<c.length;i++)
{
if(c[i].checked == true)
break;

else
{
alert("No checkbox is selected")
return false;
}
}

return(true);
}
//-->
</script>
</head>

<body>
<h1> Form validation Program</h1>

<form name="form1" onsubmit="return(validate());">


First name:
<input type="text" name="first_name" />
<br>
<br>
Last name:
<input type="text" name="last_name" />
<br>
<br>
Date of birth:
<input type="text" name="dob" value=""/>
<br>
<br>
Age:
<input type="text" name="age" value="" maxlength=2 />
<br>
<br>
Password:
<input type="password" name="password" maxlength=12 />
<br><br>
your interest:
<br>
<textarea rows="5" cols="50" name="des">
tell about yourself...
</textarea>
<br>
<br>
choose your language known:
<input type="checkbox" name="lang" value="on"> TAMIL
<input type="checkbox" name="lang" value="on"> ENGLISH
<input type="checkbox" name="lang" value="on"> KOREAN
<input type="checkbox" name="lang" value="on"> HINDI
<br><br>
Gender:
<br>
<input type="radio" name="gender" value="male"> Male<br>
<input type="radio" name="gender" value="male"> Female<br>
<br>

<input type="submit" value="submit" />

</form>
</body>
</html>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy