Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    alert() statement lets code work, remove it, code errors out

    I am a 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 routine:
    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); 
    } 
    } 
    }
    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!
    Last edited by arcanerain; 12-14-2007 at 08:34 PM. Reason: Posting with CODE tags

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    It might help if you take out the line numbers and post in CODE tags. It's really hard to see what's going on without the spacing.

  • #3
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Updated with CODE tags -- sorry...

    Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •