if(document.frmMain.POL_NO.value == "")
{
alert("Select Policy Number");
document.frmMain.ENDT_NO.value="";
document.frmMain.POL_NO.focus();
return false;
}
Can anyone explain the above code to me? I am new to Javascript.
It appears to be a bit of validation code to make sure a user has entered a value for an item referred to as “Policy Number”. It is the sort of code that gets called when submitting a form to check that the values the user has entered are valid.
In detail:
Only run this code if the item called in POL_NO the form called frmMain doesn’t have a value yet.
Display a message to tell the user that they need to enter a value.
Set the ENDT_NO item of frmMain to a blank value.
Set the focus to the POL_NO item (the same as the user tabbing to it or clicking on it).
Return false to the code that called the function that this code is in. If this code is used in the event handler for the submit button on a form then returning false will stop the form from being submitted to the server until the POL_NO item has a value.