...

View Full Version : using alert causes different behavior than not using it



therubberduckie
08-26-2007, 06:14 AM
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!

Philip M
08-26-2007, 08:59 AM
Surely what is wrong is that
true;and false;

should read return true; and return false;

therubberduckie
08-26-2007, 09:04 AM
Nope. Tried that too! (retried it again after your post), but thanks for taking a stab. I'll admit it's an odd one...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum