therubberduckie
08-26-2007, 05: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!
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!