473,410 Members | 1,872 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,410 software developers and data experts.

Dynamically creating input fields?

Hi there

I have a form which submits a list of data to a web-application (which then
saves to a database).
The list consists of four input fields per row.
Eg.
<field_1.1><field_2.1><field_3.1><field_4.1>
<field_1.2><field_2.2><field_3.2><field_4.2>
<field_1.3><field_2.3><field_3.3><field_4.3>
....

Now I want to allow the user to enter new rows in the list, and I have
thought about the possibility of using javascript to dynamically create a
row of empty input fields on the screen when the user clicks on a button -
is this possible, and how?

Thanks,
Peter

Jul 23 '05 #1
1 2371
Peter Kirk wrote:
Hi there

I have a form which submits a list of data to a web-application (which then
saves to a database).
The list consists of four input fields per row.
Eg.
<field_1.1><field_2.1><field_3.1><field_4.1>
<field_1.2><field_2.2><field_3.2><field_4.2>
<field_1.3><field_2.3><field_3.3><field_4.3>
...

Now I want to allow the user to enter new rows in the list, and I have
thought about the possibility of using javascript to dynamically create a
row of empty input fields on the screen when the user clicks on a button -
is this possible, and how?

Thanks,
Peter

Yes, it is. One problem, though. I cannot get entered values from the
generated input fields. However here's how:

First, create a place in your html file where the generated components
will go.

<tr id="contentPlace"></tr> Obviously, in a table row in this example.

Then generate first the <td> object and then the form elements. Add the
form elements to the <td>, add the <td> to the <tr> and add the whole
lot to the form.

var contentPlace = document.getElementById("contentPlace");
var cell = document.createElement("TD");
cell.id="contentCell";
cell.colSpan= 9;
cell.align="center";
var text1 = document.createTextNode("Auto");
var input1 = document.createElement("Input");
input1.name="auto";
input1.value="auto";
input1.type="CheckBox";

Of course, input1.type="Text"; is also valid. Then specify
input1.size=xx etc.

Now adding:

contentPlace.appendChild(cell);
cell.appendChild(text1);
cell.appendChild(input1);

I also got a reference to the form (getElementById("myform");)
and added the various form elements. No go. The elements generate
beautifully, but no input from them goes to the server.

Have a look at http://members.optusnet.com.au/~mala...CN/dealer.html
an play with the Category select element.

If you get it working, please tell me.

In the end I used hidden fields and unhide them when needed.
Cosmetically inferior, but it works.

Chris

Jul 23 '05 #2

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

Similar topics

6
by: NotGiven | last post by:
I want to learn moer of what I saw in a recent example. They create a page that created new fields/element. It's not like they were hidden and they displayed them, they were not there, then the...
2
by: djc | last post by:
On the page_load event I am querying a database and binding data to some text boxes, list boxes, and a repeater control. When the page loads it uses the value of one of the database fields (status)...
4
by: Stone Chen | last post by:
Hello, I have form that uses javascript createElement to add additional input fields to it. However, my validating script will not process new input fields because it can only find the named...
6
by: Amit Maheshwari | last post by:
I have my aspx page on which i am creating <input type=text> on client side using javascript. Now when i submit my page i need to access these controls to get the value entered by the user. the...
5
by: stellstarin | last post by:
I have a html where fields are created and added dynamically on the client side. I use the AppendChild() call to create fields dynamically. On submit i try to get the value for all the...
1
by: hardieca | last post by:
Hi, I'm building a multi-lingual CMS. The user can add as many languages as he likes. The user will be able to create sections for different content (General, News Releases, etc...) in the db...
1
verbatim
by: verbatim | last post by:
with the following page, the dynamically generated fields are not recognized when i try to submit the form, or add more elements. when i hit my submit button, the address bar has only x1 - x5 in...
7
by: Srikanth Ram | last post by:
Hi, I'm creating a PHP application. In this a dynamic table with the fields in the database is generated in a page. I have placed a checkbox in each row of the table to approve/disapprove...
4
by: mohaaron | last post by:
I can think of a lot of reasons why this might need to be done but as far as I can tell it's not possible. I've been looking for a way to add HtmlTableRows to a table using a button click for a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.