• Post Reply Bookmark Topic Watch Topic
  • New Topic

Insert more than one row in database.

 
pankaj semwal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi List[],

I have created a jsp page and used java script.I am dyanmic adding row in table from text box.Its showing the data in the row which i have entered in the textbox.But now i want to know how to insert these row in database.Please help me how to do this.

Thanks
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pankaj semwal:
But now i want to know how to insert these row in database.


please can you post that so far what you tried?
 
pankaj semwal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Below is my code which adding row dynamically on clicking button.I want to insert these data in database.Any idea how to do this kind of work.



function addrows(cid)

//here we point the tbody variable to the table
var tbody = document.getElementById(cid).getElementsByTagName("TBODY")[0];

//here we create a row element
var row = document.createElement("TR");

//here we create the first cell element
var t1 = document.createElement("TD");

//here we popuate the first cell with 'Test1'
t1.innerHTML=document.getElementById("t1").value;

//here we create the second cell element
var t2 = document.createElement("TD");

//here we popuate the first cell with email@server.com'
t2.innerHTML=document.getElementById("t2").value;

var t3 = document.createElement("TD");

t3.innerHTML=document.getElementById("t3").value;
//here we append the cells to the created row element
row.appendChild(t1)
row.appendChild(t2)
row.appendChild(t3);
document.getElementById("t1").value="";
document.getElementById("t2").value="";
document.getElementById("t3").value="";
//here we append the created row element to the table
tbody.appendChild(row)
 
Patricia Samuel
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pankaj semwal:
Hi,

Below is my code which adding row dynamically on clicking button.I want to insert these data in database.Any idea how to do this kind of work.



function addrows(cid)

//here we point the tbody variable to the table
var tbody = document.getElementById(cid).getElementsByTagName("TBODY")[0];

//here we create a row element
var row = document.createElement("TR");

//here we create the first cell element
var t1 = document.createElement("TD");

//here we popuate the first cell with 'Test1'
t1.innerHTML=document.getElementById("t1").value;

//here we create the second cell element
var t2 = document.createElement("TD");

//here we popuate the first cell with email@server.com'
t2.innerHTML=document.getElementById("t2").value;

var t3 = document.createElement("TD");

t3.innerHTML=document.getElementById("t3").value;
//here we append the cells to the created row element
row.appendChild(t1)
row.appendChild(t2)
row.appendChild(t3);
document.getElementById("t1").value="";
document.getElementById("t2").value="";
document.getElementById("t3").value="";
//here we append the created row element to the table
tbody.appendChild(row)


Hi Pankaj,
it must be calling addrows method everytime you add a new row. In the end of this function, you can call a method that will insert the three values in the database. It can be done with the help of AJAX.

Cheers,
[ December 03, 2008: Message edited by: Patricia Samuel ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!