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
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    using alert causes different behavior than not using it

    I am doing some dynamic form building, and one of the things I need to do, is to capture all the input the user has already done so that once the new form elements are added I can replace them.

    In my testing I was using some alert() functions to verify things were going right. Well when I removed the alerts things went haywire.

    Here is the code that works:
    function storeValues(valuesArray)
    {
    var numContacts = document.getElementById("ContactCount").value;

    for(var i = 0; i < numContacts; i++)
    {
    var element = "txt_username" + i;
    valuesArray[i] = document.inputform["txt_username" + i].value;
    }
    true;
    }
    function retrieveValues(valuesArray)
    {
    var numContacts = (document.getElementById("ContactCount").value - 1);

    for(var i = 0; i < numContacts; i++)
    {
    document.inputform["txt_username" + i].value = valuesArray[i];
    }
    true;
    }
    function doClickEvents(itemNum)
    {
    values = new Array();
    storeValues(values);
    addContactForm(itemNum);
    alert(values[0]);
    retrieveValues(values);
    false;
    }

    And if I remove the Alert (near the bottom), then it stops restoring the values in the array. I have tried everything I can think of regarding possible variable scope, return values, etc... I can't seem to get it work. I tried searching around the interwebs but came up empty.

    Here is what does NOT work, but what I would like the code to look like:
    function storeValues(valuesArray)
    {
    var numContacts = document.getElementById("ContactCount").value;

    for(var i = 0; i < numContacts; i++)
    {
    var element = "txt_username" + i;
    valuesArray[i] = document.inputform["txt_username" + i].value;
    }
    true;
    }
    function retrieveValues(valuesArray)
    {
    var numContacts = (document.getElementById("ContactCount").value - 1);

    for(var i = 0; i < numContacts; i++)
    {
    document.inputform["txt_username" + i].value = valuesArray[i];
    }
    true;
    }
    function doClickEvents(itemNum)
    {
    values = new Array();
    storeValues(values);
    addContactForm(itemNum);
    retrieveValues(values);
    false;
    }

    Please help!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,920
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Surely what is wrong is that
    true;and false;

    should read return true; and return false;

  • #3
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nope. Tried that too! (retried it again after your post), but thanks for taking a stab. I'll admit it's an odd one...


  •  

    Posting Permissions

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