Forum Moderators: open
function showPreview(vid) {
var oForm = document.forms[0];
var iNumElems = oForm.elements.length;
var oElem;
eval("divPreview" + vid + ".style.visibility = 'visible'");
for (var i = 0; i < iNumElems; i++) {
oElem = oForm.elements[i];
if (("SELECT" == oElem.tagName) && =
(oElem.name!= "descript_" + vid) &&
(oElem.name!= "DescriptionAdj_" + vid)){
oElem.style.visibility = 'hidden';
}
}
}
oElem should be a local variable (a little faster) 2) You could use a reg exp to do both those name tests at once, avoiding the concatenations too.
Compile the reg exp at the top of the loop:
var regNames = new RegExp("^(descript_"+vid+"¦DescriptionAdj_"+vid+")$"); Then the test is:
[red]![/red]regNames.test(oElem.name) But, I suspect that the whole process has started on the wrong foot.
So I recommend ignoring the above, and starting again.
It seems that you are toggling the visibility of pairs of elements. There is no need to go through all the thousands of elements hiding elements that are already hidden. The better - and in cases like this, only sensible - toggling approach is to store the currently visible elements in a couple of global variables. When you want to switch to a new pair, just hide the elements held in the variables, show your new pair, then put them into your storage variables. It will take no time at all.