|
I am a novice/almost-to-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, line 20) 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() (line 23) statement after the HTML is created, but when I remove, the code errors out.
I have tried the setTimeout() (line 25) statement, but I cannot grab the element --- undefined or null is returned.
Here is the routine:
1. function editQuery() {
2. var f;
3. var x;
4. var myForm = document.forms[0];
5. // Get the row filters that were used in the last query...
6. for (f = 1; f < 16; f++) {
7. var filter = eval("myForm.FilterList_" + f);
8. if (filter.selectedIndex > 0) {
9. var methodElement = element("FilterMethod_" + f);
10. var methodIndex = methodElement.selectedIndex;
11. var savedFilterMethodValue = methodElement.options[methodIndex].text;
12. var choicesElement = element("FilterChoices_" + f);
13. var choicesIndex = choicesElement.selectedIndex;
14. if (isNaN(choicesIndex)) {
15. var savedFitlerValues = choicesElement.value;
16. }
17. else {
18. var savedFitlerValues = choicesElement.options[choicesIndex].text;
19. }
20. updateFilters(filter); // update the filters
21. // take the saved methods and values and then update the selections
22. // Alert here makes the code work...
23. // alert("Try this");
24. // Wait for HTML...
25. setTimeout(completeEdit, 1000);
26. function completeEdit() {
27. // Since the object was updated, get the object again...
28. var methodElement = element("FilterMethod_" + f);
29. for (x = 0; x < methodElement.options.length; x++) {
30. if (methodElement.options[x].text == savedFilterMethodValue) {
31. methodElement.options[x].selected = true;
32. break;
33. }
34. else {
35. methodElement.options[x].selected = false;
36. }
37. }
38. // Since the object was updated, get the object again...
39. var choicesElement = element("FilterChoices_" + f);
40. for (x = 0; x < choicesElement.options.length; x++) {
41. if (choicesElement.options[x].text == savedFitlerValues) {
42. choicesElement.options[x].selected = true;
43. break;
44. }
45. else {
46. choicesElement.options[x].selected = false;
47. }
48. }
49. // Only display next row if f = 2...
50. // If only one row was used, no reason display the next row...
51. if (f == 2) {
52. displayNextFilter(f - 1); // display it
53. }
54. }
55. clearTimeout(timeOut);
56. }
57. }
58. }
Do I have to pass the object (the form, the elements) to the completeEdit() (line 26) function in the setTimeout() statement?
I could use some help...
Thanks!
<Added>
I am a novice, almost to 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. It seems that the form is the only element I can get a handle on --- everything else is undefined or null...
Here is the code:
[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[x].text == savedFilterMethodValue) {
methodElement.options[x].selected = true;
break;
}
else {
methodElement.options[x].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[x].text == savedFitlerValues) {
choicesElement.options[x].selected = true;
break;
}
else {
choicesElement.options[x].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);
}
}
}
[/CODE]
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
|
|
|
|
|
|
|
// |