Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Save HTML table data to database  RSS feed

 
Viky Kizz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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>
<tr>
<td>
<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()">
</td>
</tr>
</table>
<table id="testgrid" borderColor=#3E94C1 cellSpacing=0 width='100%' cellPadding=0 border=1>
<tr>
<td>Employee Name</td>
<td>Employee ID</td>
<td>Designation</td>
<td>Process Name</td>
<td>LOB Name</td>
<td>LOB Head</td>
</tr>
</table>
</div>
**JS code**

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

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

var name = document.getElementById("requestedForNameID").value;
alert("Hello"+name);
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;
alert(rowcount);
rowcount=rowcount++;
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="Text1";
cell2.innerHTML="Text2";
cell3.innerHTML="Text3";
cell4.innerHTML="Text4";
cell5.innerHTML="Text5";
cell6.innerHTML="Text6";*/
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
Greenhorn
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?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!