JavaScript Val
JavaScript Val
EXPERIMENT NO:-03
Roll NO.:-
**********************************************************************************
1. Client-Side Validation:
Definition: This type of validation occurs in the user’s browser before the data is sent to the
server. JavaScript is commonly used to perform client-side validation.
Purpose: It provides immediate feedback to the user, allowing them to correct errors in real-
time without needing to reload the page.
Examples: Checking if required fields are filled, verifying email format, and ensuring
password strength.
JavaScript is a powerful tool for client-side form validation, offering several key benefits:
Instant Feedback: JavaScript allows for real-time validation, providing users with immediate
feedback as they fill out the form. This reduces frustration by highlighting errors instantly and
guiding users to correct them without submitting the form multiple times.
Enhanced Interaction: By validating form data on the client side, users experience smoother
interactions, leading to higher satisfaction and engagement.
2. Real-Time Feedback:
Error Highlighting: JavaScript can dynamically highlight erroneous fields, display helpful error
messages, and even suggest corrections. This real-time interaction helps users understand
what needs to be fixed and how.
Interactive Elements: Using JavaScript, you can create more interactive form elements, such
as showing/hiding sections based on user input, enhancing the overall usability of the form.
Efficiency: By catching errors on the client side, JavaScript reduces the number of incorrect
form submissions sent to the server. This decreases server load and optimizes the processing
of valid data.
Resource Management: Validating forms on the client side ensures that only clean and
properly formatted data reaches the server, making better use of server resources and
improving performance.
Program:
<html>
<head>
<title>form validation</title>
</head>
<body>
<script>
function data1()
var a = document.getElementById("n1").value;
var b = document.getElementById("n2").value;
var c = document.getElementById("n3").value;
var d = document.getElementById("n4").value;
var e=document.getElementById("n5").value;
if(a==""||b==""||c==""||d==""||e=="")
else if(b.length<10||b.length>10)
else if(isNaN(b))
else if(c!=d)
{
alert("Enter Same Password");
</script>
<form onsubmit="data1()">
</form>
</body>
</html>
Output: