I am posting this here, because of the 5 other JS forums, no one has answered this — I am hoping I might catch a break here… Thanks in advance!!
I am an intermediate-level JavaScript guy, so much of this is new to me. I appreciate your patience reading this.
I have a routine that creates some HTML on the fly (updateFilters() function) and after the HTML is created, I attempt to access some fields (elements) on the form itself.
I works fine if I place an alert() statement after the HTML is created, but when I remove, the code errors out.
I have tried the setTimeout() statement, but I cannot grab the element — undefined or null is returned.
Here is the code:
function editQuery() {
var f;
var x;
var myForm = document.forms[0];
// Get the row filters that were used in the last query…
for (f = 1; f < 16; f++) {
var filter = eval(“myForm.FilterList_” + f);
if (filter.selectedIndex > 0) {
var methodElement = element(“FilterMethod_” + f);
var methodIndex = methodElement.selectedIndex;
var savedFilterMethodValue = methodElement.options[methodIndex].text;
var choicesElement = element(“FilterChoices_” + f);
var choicesIndex = choicesElement.selectedIndex;
if (isNaN(choicesIndex)) {
var savedFitlerValues = choicesElement.value;
}
else {
var savedFitlerValues = choicesElement.options[choicesIndex].text;
}
updateFilters(filter); // update the filters
// take the saved methods and values and then update the selections
// Alert here makes the code work…
// alert(“Try this”);
// Wait for HTML…
setTimeout(completeEdit, 1000);
function completeEdit() {
// Since the object was updated, get the object again…
var methodElement = element(“FilterMethod_” + f);
for (x = 0; x < methodElement.options.length; x++) {
if (methodElement.options.text == savedFilterMethodValue) {
methodElement.options.selected = true;
break;
}
else {
methodElement.options.selected = false;
}
}
// Since the object was updated, get the object again…
var choicesElement = element(“FilterChoices_” + f);
for (x = 0; x < choicesElement.options.length; x++) {
if (choicesElement.options.text == savedFitlerValues) {
choicesElement.options.selected = true;
break;
}
else {
choicesElement.options.selected = false;
}
}
// Only display next row if f = 2…
// If only one row was used, no reason display the next row…
if (f == 2) {
displayNextFilter(f - 1); // display it
}
}
clearTimeout(timeOut);
}
}
}
Do I have to pass the object (the form, the elements) to the completeEdit() function in the setTimeout() statement?
I could use some help…
Thanks!
Dan