G
Geoff
function AddBlock() {
I have a dynamic form that allows the user to click an 'add' button to
add extra groups of input fields. These fields are name, phone, and
type.
Let's say that a user enters one Point of Contact, then wants to enter
another by clicking the 'add' button. I want to save the previously
entered data into an array structure. I'm having trouble with the below
snippet of code:
// Save previously entered data here
var formObj = document.dynoPoc;
for (i=0,j=0; i<loops; i++) {
data[j] = formObj.POC_name.value;
j++;
data[j] = formObj.POC_phone1.value;
j++;
data[j] = formObj.POC_type.value;
j++;
}
What I expect to happen for the very first line of the loop is that the
line 'data[j] = formObj.POC_name.value;'
gets evaluated to 'data0 = formObj.POC_name0.value;'. What seems to be
happening is 'data0 = formObj.POC_name.value;'.
This causes an error because there is no input field named 'POC_name'...
they're called 'POC_name0, POC_name1, ...POC_name[n] depending on the
number of times you click the 'add' button.
Any suggestions:
Thanks
I have a dynamic form that allows the user to click an 'add' button to
add extra groups of input fields. These fields are name, phone, and
type.
Let's say that a user enters one Point of Contact, then wants to enter
another by clicking the 'add' button. I want to save the previously
entered data into an array structure. I'm having trouble with the below
snippet of code:
// Save previously entered data here
var formObj = document.dynoPoc;
for (i=0,j=0; i<loops; i++) {
data[j] = formObj.POC_name.value;
j++;
data[j] = formObj.POC_phone1.value;
j++;
data[j] = formObj.POC_type.value;
j++;
}
What I expect to happen for the very first line of the loop is that the
line 'data[j] = formObj.POC_name.value;'
gets evaluated to 'data0 = formObj.POC_name0.value;'. What seems to be
happening is 'data0 = formObj.POC_name.value;'.
This causes an error because there is no input field named 'POC_name'...
they're called 'POC_name0, POC_name1, ...POC_name[n] depending on the
number of times you click the 'add' button.
Any suggestions:
Thanks