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.dynoPo c;
for (i=0,j=0; i<loops; i++) {
data[j] = formObj.POC_nam e[i].value;
j++;
data[j] = formObj.POC_pho ne1[i].value;
j++;
data[j] = formObj.POC_typ e[i].value;
j++;
}
What I expect to happen for the very first line of the loop is that the
line 'data[j] = formObj.POC_nam e[i].value;'
gets evaluated to 'data0 = formObj.POC_nam e0.value;'. What seems to be
happening is 'data0 = formObj.POC_nam e.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.dynoPo c;
for (i=0,j=0; i<loops; i++) {
data[j] = formObj.POC_nam e[i].value;
j++;
data[j] = formObj.POC_pho ne1[i].value;
j++;
data[j] = formObj.POC_typ e[i].value;
j++;
}
What I expect to happen for the very first line of the loop is that the
line 'data[j] = formObj.POC_nam e[i].value;'
gets evaluated to 'data0 = formObj.POC_nam e0.value;'. What seems to be
happening is 'data0 = formObj.POC_nam e.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
Comment