In this short code we are going to process a user form. and going to show an error message and change the color of a field name by using javascript.
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Form Processing : with alert Highlight field name which is not filled by user</title>
<script language="javascript" type="text/javascript">
function CheckTheForm() {
var result = true;
var msg="";
if (document.frmTest.name.value=="") {
msg+="Please enter Name! \n";
document.frmTest.name.focus();
document.getElementById('title').style.color="red";
result = false;
}
if (document.frmTest.eml.value=="") {
msg+="Email is Required!\n";
document.frmTest.eml.focus();
document.getElementById('eml').style.color="red";
result = false;
}