0% found this document useful (0 votes)
6 views3 pages

p36065 File

The document outlines a JavaScript program for form validation, focusing on user input for name and password. It checks that the name is not empty and that the password is at least six characters long, providing visual feedback for each validation. The form submission is controlled by the validate function, which returns a status indicating whether the input is valid.

Uploaded by

devanshipatel514
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)
6 views3 pages

p36065 File

The document outlines a JavaScript program for form validation, focusing on user input for name and password. It checks that the name is not empty and that the password is at least six characters long, providing visual feedback for each validation. The form submission is controlled by the validate function, which returns a status indicating whether the input is valid.

Uploaded by

devanshipatel514
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/ 3

AWP(3161611) 221240116065

Practical – 3

AIM : Write a program to perform JavaScript form validation.

<html>
<head>
<title>Form Validation</title>
<script>
function validate()
{
var name = document.f1.name.value;
var password = document.f1.password.value;
var status = true;
if (name.length < 1)
{
document.getElementById("nameloc").innerHTML =
'<img src="unchecked.png" style="width:15px; height:15px;"/>Please enter your
name';
status = false;
} else
{
document.getElementById("nameloc").innerHTML =
'<img src="checked.png" style="width:15px; height:15px;"/>';
}
// Password validation
if (password.length < 6)
{ document.getElementById("passwordloc").innerHTML
=
'<img src="unchecked.png" style="width:15px; height:15px;"/> Password must
be at least 6 characters';
SPCE(IT) 1
AWP(3161611) 221240116065

SPCE(IT) 2
AWP(3161611) 221240116065
status = false;
}
else {
document.getElementById("passwordloc").innerHTML=
'<img src="checked.png" style="width:15px; height:15px;"/>';
}
return status; }
</script>
</head>
<body>
<center>
<form name="f1" action="#" onsubmit="return validate()">
<table>
<tr>
<td>Enter your name :</td>
<td>
<input type="text" name="name"/>
<span id="nameloc"></span>
</td></tr>
<tr>
<td>Enter your password :</td>
<td>
<input type="password" name="password"/>
<span id="passwordloc"></span>
</td> </tr>
<tr><td colspan="2">
<input type="submit" value="Register"/>
</td></tr>
</table>

SPCE(IT) 3

You might also like