We can do validation of a form which is created in html by using javascript.
In below example if we do not put any thing in fname field, then validateName function will alert a message that Name field is empty.
eg:-
function validateName() {
var n = document.forms["firstform"]["fname"].value;
if (n == null || n == "") {
alert("Name field is empty");
return false;
}
}
Html code
<form name="firstform" action="test.amp";form.asp" onsubmit="return validateName()" method="post">
Name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>
0 Comment(s)