EDIT: After pulling my head out of the forest for a bit and pouring myself a drink, I realized the problem cannot be in my code. Indeed, it must be one of the elements I am trying to access that is not hit by the first color change because it is not blank :0) Sure enough, the case was a dropdown that was not blank. I'm still not sure WHY that dropdown was giving me a problem, but I don't want to think about it right now.
************************************************** **********************************
This one has really got me puzzled.
I am doing a simple validation on a rather long form. The required field names have been put into an array which is looped through to look for blank field entries and color the background of a table cell that holds the field title.
All works fine as far as coloring the cells red. However, if the user fills in some, but not all, of the blank fields, the validation code needs to now set the title cells of the previously blank fields to white. No matter where I put the code for the white background (even directly under "Cell = document.getElementById(CellName);"), it renders the entire code useless.
The wierd stuff with the "First Element" is because the form spans two divs that are toggled (block on/off) with a tab, so if the first blank element is on page 2, it needs to focus there. If you take this code out and bare-bone it, the results are still the same.
Code:
var Page2Key = 14;
var Required = new Array("CompanyName","CompanyAddr","CompanyCity","CompanyState","CompanyZip","ContactName","ContactPhone","ContactEmail","PUAddress","PUCity","PUState","PUZip", "PickupDate","DockHour","DocName","Shipper","ShipAddr","ShipCity","ShipState","ShipZip","ShipPhone","Consignee","ConsAddr","ConsCity","ConsState","ConsZip","ConsPhone");
var x = Required.length;
var FirstElement = "";
var FirstElementPage = "";
var CellName = "";
var Cell = "";
var P = document.PURForm;
for(i=0;i<x;i++)
{
CellName = Required[i] + "Title";
Cell = document.getElementById(CellName);
if(P.elements[Required[i]].value == "")
{
if(FirstElement == "")
{
FirstElement = Required[i];
if(i < Page2Key) // "DocName"
{
FirstElementPage = "PUR";
}
else
{
FirstElementPage = "DET";
}
}
Cell.style.backgroundColor="#FF4A4A";
}
else
{
Cell.style.backgroundColor="#FFFFFF";
}
}
if(FirstElement != "")
{
alert("Please enter values in the fields colored red");
ToggleView(FirstElementPage);
document.getElementById(FirstElement).focus();
return false;
}