function Validation(Values) // Array of Values to check //
for(var i=0;i<Values.length;i++) // for each value in array //
var elm = document.getElementById(Values[i]) // DOM element with the id of the array item (ie, id='PassWord')
if(elm.value == '') // if it does not have a value set//
alert('Please Enter A ' + Values[i]);
return false; // will tell the onsubmit to return false and alert the first error//
<form onsubmit="return Validation(['UserName','PassWord'])" action='LoginPage.html' method="POST">
<dd><input type="text" name="us" id="UserName"/></dd>
<dd><input type="text" name="us" id="PassWord"/></dd>
<button type="submit" id="sb">Submit</button>
But in the browser this could be changed by the user to something like:
so you cannot use js validation to stop invalid inputs being inputted into a database or such.
Hope this helps!