473,379 Members | 1,201 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Dynamic Form Question

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[i].value;
j++;
data[j] = formObj.POC_phone1[i].value;
j++;
data[j] = formObj.POC_type[i].value;
j++;
}

What I expect to happen for the very first line of the loop is that the
line 'data[j] = formObj.POC_name[i].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

Jul 20 '05 #1
2 1439
"Geoff" <gt*******@netscape.net> wrote in message
news:bn*********@enews2.newsguy.com...
<snip>
What I expect to happen for the very first line of the loop is
that the line 'data[j] = formObj.POC_name[i].value;'
gets evaluated to 'data0 = formObj.POC_name0.value;'.

<snip>

Why do you expect that to happen? That is not how square bracket syntax
works in any JavaScript context. Look at (and follow the link from):-

<URL: http://www.jibbering.com/faq/#FAQ4_39 >

Richard.
Jul 20 '05 #2
Correct, I was having a brain fart! It works now.

Richard Cornford wrote:
"Geoff" <gt*******@netscape.net> wrote in message
news:bn*********@enews2.newsguy.com...
<snip>

What I expect to happen for the very first line of the loop is
that the line 'data[j] = formObj.POC_name[i].value;'
gets evaluated to 'data0 = formObj.POC_name0.value;'.

<snip>

Why do you expect that to happen? That is not how square bracket syntax
works in any JavaScript context. Look at (and follow the link from):-

<URL: http://www.jibbering.com/faq/#FAQ4_39 >

Richard.


Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: CAD Fiend | last post by:
Hello, Well, after an initial review of my database by my client, they have completely changed their minds about how they want their form. As a result, I'm having to re-think the whole process....
6
by: MikeY | last post by:
Hi Everyone, Does anyone know where I can get my hands on a sample with source code of a simple dynamic button control in C# Windows form. I am looking for a sample that uses a class library...
1
by: sleigh | last post by:
Hello, I'm building a web application that will build a dynamic form based upon questions in a database. This form will have several different sections that consist of a panel containing one to...
4
by: Venus | last post by:
Hello, Thanks for your reply. I understand that a control can be created dynamically in several ways: 1) using StringBuilder 2) using Controls.Add 3) using ASP PlaceHolder But this is just...
3
by: Tyler Carver | last post by:
I am trying to use some dynamic controls that are built and then added to tables. The problem that I am having is the timing of when I can populate the controls and have the state remain after a...
3
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which...
8
by: George Meng | last post by:
I got a tough question: The backgroud for this question is: I want to design an application works like a engine. After release, we can still customize a form by adding a button, and source code...
5
by: Nate | last post by:
Good Morning All, What we have is a dynamic business object that has varying numbers and types of properties. What it models is a generic saleable product. Not all products have the same...
1
by: Mike Collins | last post by:
I have a web form that has most of the UI designed. On this form, some of the labels, textboxes, dropdowns, etc. will be added dynamically, depending on what extra bits of data the user decides...
6
by: mcgrew.michael | last post by:
I hope this is the right group. I am very new to ASP so this is probably a stupid question. I have some vbscript that query's AD and populates a recordset. I know the recorset contains the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.