I have a form with multiple drop down boxes. All start with a default value of "-", but once the form is submitted, non can have that value. When this happens, the label for the drop down box gets changed to red. I'd like to put both the label names and drop down box names in arrays, and then loop through the sets of arrays to check each one. I have many more than 3 drop down boxes in my actual code. It works fine when I copy/paste the same code over and over again but change the label and box names, but if this can be avoided, I'm sure it'll be much better coding practice.
In bold is where I'm having my problem. I know I can't enter the array variable as I have it there, but I don't know how to do it. The line below it works fine, because you pass the name in parenthesis, so inputting the array variable makes sense.
Can anyone help? Thanks!
In bold is where I'm having my problem. I know I can't enter the array variable as I have it there, but I don't know how to do it. The line below it works fine, because you pass the name in parenthesis, so inputting the array variable makes sense.
Can anyone help? Thanks!
Code:
function validate_template() {
valid = true;
var dropDownNum = 3;
var dropDowns=new Array(dropDownNum);
var dropDownsLabel=new Array(dropDownNum);
dropDowns[0]="name";
dropDowns[1]="occupation";
dropDowns[2]="title";
dropDownsLabel[0]="name";
dropDownsLabel[1]="occupation";
dropDownsLabel[2]="title";
for(i=0; i<dropDownNum+1; i++) {
if (document.templateForm.[b]dropDowns[i][/b].value == "-")
{
var l = document.getElementById(dropDownsLabel[i]);
l.style.color="red";
l.style.fontWeight="bold";
valid = false;
}
}
if (valid == false)
{
alert("Template data incomplete");
}
return valid;
}