Validation is most important part any website while creating
a form. There are lots of methods and processes of JavaScript or jquery.
I have implemented basic validation as simple as possible which
can be used for empty fields check. You need to call just little function and
achieved validation on various HTML form tags.
Code
<html>
<head>
<title>Girfa :
Javascript Validation</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
var
Flag = true;
function
Validate() {
Flag = true;
if
($("#txtRoll").val() == "")
AddCss("txtRoll");
if
($("#ddlClass").val() == "")
AddCss("ddlClass");
if
($("#txtMessage").val() == "")
AddCss("txtMessage");
}
function AddCss(id) {
Flag = false;
$("#"
+ id).css("border", "solid 1px red");
$('#'
+ id).animate({
'marginLeft':
"+=10px", //moves
right
}, 100);
$('#'
+ id).animate({
'marginLeft':
"+=-10px", //moves right
}, 100);
$('#'
+ id).animate({
'marginLeft':
"+=10px", //moves
right
}, 100);
$('#'
+ id).animate({
'marginLeft':
"+=-10px", //moves right
}, 100);
}
function
RemoveCss(id) {
$("#"
+ id).css("border", '');