By the way, my professor deliberately did not teach us how to do this, because he wants us to explore it ourselves.
Which should give you a hint of searching a little deeper. In any case, I will not comment on each line, but I will offer some tips.
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
This is a proprietary way to create a Microsoft XML document, and it usually terminates in try..catch, since different ActiveXO objects are provided in different versions of IE. You also need to look for document.implementation.createDocument .
//DEFINE LOAD METHOD function LoadXML(xmlFile) { xmlDoc.load(xmlFile);
You might want to check the async parameter.
xmlObj = xmlDoc.documentElement; } //declare & initialize array var arrPerson = new Array();
It is believed that it is better to use an array literal: ... = [];
//initialize array w/ xml function initialize_array() { LoadXML("PersonXML.xml"); var x = 0; while (x < xmlObj.childNodes.length)
Getting the length of xmlObj.childNodes in each loop is inefficient, consider storing the length and comparing with this value.
{ var tmpArr = new Array(xmlObj.childNodes(x).getAttribute("Usrname"), xmlObj.childNodes(x).getAttribute("Pswd"), xmlObj.childNodes(x).getAttribute("FirstName"), xmlObj.childNodes(x).getAttribute("LastName"), xmlObj.childNodes(x).getAttribute("DOB"), xmlObj.childNodes(x).getAttribute("Gender"), xmlObj.childNodes(x).getAttribute("Title"));
It is inefficient to access xmlObj.childNodes (x) several times. Save the link and reuse it.
arrPerson.push(tmpArr);
You can assign values โโdirectly to arrPerson and get rid of tmpArr.
x++;
Using a plain for loop will increment x for you.
} } //Validation function LogInVal(objtxt) { if(objtxt.value.length == 0) { objtxt.style.background = "red"; return 1; } else { objtxt.style.background = "white"; return 0; } }
Not all browsers allow you to set the background color of input elements.
//main validation function MainVal(objForm) { var errmsg = "empty field"; var errmsg2 = "Incorrect Username and Password";
You may need a more efficient way of naming error messages and linking them to other information for this message. An object can do the job.
var msg = "You have logged in successfully"; var errCount = 0; var usrn = document.getElementById("usrname1").value; var pswd = document.getElementById("pswd1").value; errCount += LogInVal(objForm.usrname); errCount += LogInVal(objForm.pswd); initialize_array(); if (errCount != 0) { alert(errmsg); return false; } else if(authentication(usrn, pswd) == true)
The authentication() function returns true or false, so you do not need to compare it with anything, you can just check the return value (i.e. there is no need for == true above).
{ alert(msg); return true; setCookie('invalidUsr',' ttttt'); } else { alert(errmsg2); return false; } }
Instead of showing warning messages one at a time in a warning, consider placing them in a document next to the elements to which they relate. Thus, the user can see messaeg when fixing the error.