ASP.NET Javascript Client Side Validation


<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Validation On Submit</title>
<script language=”JavaScript”>
function validate() {
n1 = document.Form1.txtN1.value
n2 = document.Form1.txtN2.value
if (n1 == “” || n2 == “”) {
alert(“Please enter all the values”)
return false; //Form is not Submitted
}
return true; //Form is Submitted
}
function div_Click() {
if (document.Form1.txtN2.value == “0”) {
alert(“Denominator cannot be zero”);
return false; //Form is not Submitted
}
return true; //Form is Submitted
}
</script>
</head>
<body>
<form name=”Form1″ onsubmit=”return validate()”>
N1
<input type=”text” name=”txtN1″ /><br />
N2
<input type=”text” name=”txtN2″ /><br />
<input type=”submit” value=”Add” />
<input type=”submit” value=”Sub” />
<input type=”submit” value=”Mul” />
<input type=”submit” value=”Div” onclick=”return div_Click()” />
<input type=”submit” value=”Delete” onclick=”return confirm(‘Are you sure’)” />

Leave a Reply