I have previously asked a question with the same title line but my situation and purpsse are different this time. I mean to be creating a function to go back over a form, identify blank required fields, change their borders to red then go back and give focus to the first one.
There are actually five possible fields that could be blank but I only included the first here becauxe it has no problem identifying the blank fields and making the borders red. The problem is with the last if() statement where I am trying to return focus() to the first blank field. Since nothing is in parenthesis I am uncertain how to distinguish that I want the value of variable 'firstBlankFiel d' substitued for the name of the variable in my getElementById( ) statement. Essentially I need to do a macro substitution and I don't know how. Can anybody offer a solution?
Code:
function checkUnitFields(x){
var num=x; // item number
var firstBlankField=null; // variable to be used to move focus to first field that needs attention
var secondBlankField=null; // variable to be used to move focus to second field that needs attention
var thirdBlankField=null; // variable to be used to move focus to third field that needs attention
var fourthBlankField=null; // variable to be used to move focus to fourth field that need attention
var fifthBlankField=null; // variable to be used to move focus to fifth field that needs attendtion
if(isEmpty(document.getElementById('modelYear'+num).value)==true){
document.getElementById('modelYear'+num).style.border="1px solid #FF0000";
if(firstBlankField==null){
firstBlankField="modelYear";
}
}
if(isEmpty(firstBlankField)!=true){
document.getElementById(firstBlankField).focus();
}
Comment