Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Save HTML table data to database  RSS feed

Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have a HTML table whose rows are getting generated through javascript function. I want to save this data in the table rows.

Can some one tell me how to do this?

**HTML Code**
<div style="width:100%;height:100%;border:1px solid black; overflow-x:scroll; overflow-y:scroll; padding:0">
<table border=0>
<input type="button" name="add_details" id="add_details" value="Add" onclick="AddDetails()">
<input type="button" name="delete_details" id="delete_details" value="Delete" onclick="DeleteDetails()">
<table id="testgrid" borderColor=#3E94C1 cellSpacing=0 width='100%' cellPadding=0 border=1>
<td>Employee Name</td>
<td>Employee ID</td>
<td>Process Name</td>
<td>LOB Name</td>
<td>LOB Head</td>
**JS code**

//Function to add details to grid
function AddDetails()
alert("Please wait");

var r=document.getElementById("requestedForEmpID").value;

var name = document.getElementById("requestedForNameID").value;
var empID= document.getElementById("requestedForEmpID").value;
var empdesg=document.getElementById("requestedfordesignationID").value;
var process=document.getElementById("processNameID").value;
var lobname=document.getElementById("lobNameID").value;
var lobhead=document.getElementById("lobHeadID").value;
alert("Values Fetched "+name);
var table=document.getElementById("testgrid");
var form=document.getElementById("count");
var rowcount=table.rows.length;
var row=table.insertRow(rowcount);

var cell1=row.insertCell(0);
var cell2=row.insertCell(1);
var cell3=row.insertCell(2);
var cell4=row.insertCell(3);
var cell5=row.insertCell(4);
var cell6=row.insertCell(5);

cell1.innerHTML="<input type='text' id='IDEmpName_"+rowcount+"' value='"+name+"'>";
cell2.innerHTML="<input type='text' id='IDEmpID_"+rowcount+"' value='"+empID+"'>";
cell3.innerHTML="<input type='text' id='IDEmpDesg_"+rowcount+"' value='"+empdesg+"'>";
cell4.innerHTML="<input type='text' id='IDEmpProcess_"+rowcount+"' value='"+process+"'>";
cell5.innerHTML="<input type='text' id='IDEmpLob_"+rowcount+"' value='"+lobname+"'>";
cell6.innerHTML="<input type='text' id='IDEmpLobHead_"+rowcount+"' value='"+lobhead+"'>";

When i press submit button in my form of JSP, how can i access table data?
Viky Kizz
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know how would i access my table elements in my Servlet?
Author and ninkuma
Posts: 66424
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You wouldn't. You'd send the data that's pertinent to a servlet via an Ajax call when you want it to be saved. HTML is a display format, not a data format; you wouldn't send HTML.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!