Collect data and add to table

Posted on 2009-02-17
Last Modified: 2012-05-06
Trying to find a way to collect data on a screen and when user clicks a add button, drop it into a table below it.  Then user could repeat the process over and over until finished.   Once user is finished, will click a submit button and then will send to a java servlet which will process all the new requests.

I know I could do a submit button then send to servlet and the wrap around back, but trying to cut down on the network traffic and also make the application more user friendly.  Using java and jsp's.




Then on same form,  a table below it which will show each time the user adds another user.  

Name                       Address                       State
John Smith               114 N. Ash                   MO
Fred Flintstone         2912 S. Willow            KS

Question by:TheVeee
    LVL 9

    Accepted Solution

    Not tooooo hard.  For your Add button, first, get a reference to your table... the easiest way is to give it an ID.

    var dataTable = document.getElementById("MyTable");

    Then use the insertRow method to add a new row to the table.  You'll want to both display the values you're getting from the Name, Address, and State fields as well as putting the values into hidden fields on each row (so they'll actually submit).

    The basic idea is:

    var newRow = dataTable.insertRow(0);
    var newColumn = newRow.insertCell(0);
    newColumn.innerHTML = valueFromYourFields;
    newColumn.innerHTML += "<input type=\"hidden\" name=\"identifier\" value=\"" + valueFromYourFields + "\" />";
    LVL 5

    Author Comment

    Sorry, not following you.  I want this in a html table until I done getting all the additions for the user.  From reading this would be putting into a actual data store table like oracle if Im reading correctly???

    so they enter values in basic text fields, click add button and then then those fields create another <TR><TD> ........ structure in the table with the data just entered.  Once their all done, they click submit button and then I have my servlet process table entries and then do the physical add to the database....

      <td>Frank Smith</td>
      <td>2110 S. Willow</td>
    LVL 9

    Expert Comment

    No no that's javascript... creates the table right there on the client.
    LVL 5

    Author Closing Comment


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
    Preface In the first article: A Better Website Login System ( I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
    In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
    The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now