2 Answer(s)      7 years ago
Posted in : Java Beginners
im beginner,i have created form using javascript and html functionality is with every click of add button textbox shud get created,n with everyclick of delete buton the row shud get deleted tis is working fine,but i need to move the wole table from form to database with single click of submit button,only first row is being inserted i need to get the count of row n ten loop tru the elements but im unable to do so plz help me with example .


View Answers

January 8, 2010 at 3:50 PM

Hi Friend,

Try the following code:


<TITLE>Add/Delete Person</TITLE>
function addRow(){
var ptable = document.getElementById('ptablePerson');
var lastElement = ptable.rows.length;
var index = lastElement;
var row = ptable.insertRow(lastElement);

var cellLeft = row.insertCell(0);
var textNode = document.createTextNode(index);

var cellText = row.insertCell(1);
var element = document.createElement('input');
element.type = 'text'; = 'person' + index; = 'person' + index;
element.size = 30;

var cellText1 = row.insertCell(2);
var element1 = document.createElement('input');
element1.type = 'text'; = 'address' + index; = 'address' + index;
element1.size = 30;

function removeRow(){
var ptable = document.getElementById('ptablePerson');
var lastElement = ptable.rows.length;
if (lastElement > 2) ptable.deleteRow(lastElement - 1);
if(document.getElementById("psize").value>1) {
document.getElementById("psize").value = document.getElementById("psize").value-1;


<form action="insertpersons.jsp" method="post" >
<input type="hidden" name="psize" id="psize">
<table border="1" id="ptablePerson" align="center">

<td><input type="text" name="person1" id="person1" size="30" /></td>
<td><input type="text" name="address1" id="address1" size="30" /></td>

<table align="center">
<tr><td><input type="button" value="Add" onclick="addRow();" />
<input type="button" value="Remove" onclick="removeRow();" />

<input type="Submit" value="Submit" /></td></tr>

January 8, 2010 at 3:51 PM



<[email protected] import="java.sql.*"%>
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root";, "root");
Statement st=connection.createStatement();
String person ="";
String address="";
int size=0;

size = Integer.parseInt(request.getParameter("psize").toString());
for(int i=1;i<=size;i++)
person = "person"+i;
String per=request.getParameter(person).toString();
String add=request.getParameter(address).toString();
st.executeUpdate("insert into data(name,address) values('"+per+"','"+add+"')");
out.println("Data is inserted successfully");
catch(Exception e){}


Related Tutorials/Questions & Answers:
JavaScript  clone JavaScript
javascript  javascript code to dynamically add table on button click.../javascript/javascriptexamples/javascript-add-row-dynamically.shtml
Javascript  How validations are done using javascript ,with example? and interview questions on javASCRIPT
javaScript  How to open a browser window that cannot be resized? (HTML + Javascript
javascript  write a program to display implement about browsers using javascript
javascript  Hi deepak, how to write form validation on javascript
JavaScript  how to get full path of a file type in javascript
should use JavaScript? Thanks   Hi, JavaScript is scripting language that runs on browser. You have to embed JavaScript in HTML page. Please see JavaScript tutorial. Thanks
javascript  i have just learned javascript... can you tell me what kind of applications can be made by javascript?? thank you
javascript  Hi sir, This is sinduri, i want to learn javascript, so plz can u help to learn
javascript  how to set the request or session attribute in javascript head part of jsp page
javascript  hi sir, if i want to learn javascript. what concepts i want to know
JAVASCRIPT  I have one textbox and I want to validate that it must start with number(1-0). can anyone tell me a javascript for that ? thanks in advance
Javascript   Javascript to check Numeric entry in checkbox.....   Hi Please find the following code for numeric entry validation in javascript function validateBox(){ var data=document.myForm.someText.value
javaScript  . Print a table like below in JAVASCRIPT 5 x 1 = 5 5 x 2 = 10 ΓΆβ?¬Β¦ΓΆβ?¬Β¦ΓΆβ?¬Β¦. 5 x 20 = 100
javascript  hi, I was actually working on to calculate the number of days between two dates of yyyy-mm-dd format using javascript, and when i click on button then number of days should be display in textbox
javascript  passing javascript values to jsp   Hi Friend, Try the following code: form.jsp: <html> <script> function getMsg...;/script> <input type="button" onclick="getMsg();" value="Get Javascript value
this format xxx-xxx-xxxx, i want the code in javascript. as a function.   Javascript Phone Number Validation <html> <script> function..." method="post" onsubmit="javascript:return validate();"> Phone Number:<
Javascript  Dear Sir, Thank You a lot for your continuos support.Again i am in need of your help. What is the javascript code to disable a link,once... javascript or css Please help me.Urgent Regards Debasis   Hello Friend
Javascript  <html> <head> <script type="text/javascript"> function validateForm() { var sname=document.getElementById('spocname'); var scontact=document.getElementById('spoccontact'); if(sname.value.length
javascript  how to create random question using javascript?   <html> <script> function displayQuestions() { document.getElementById("text").value=" "; var Questions = new Array(20
javascript  Hi deepak, sample example on javascript form validation   <html> <script> function checkName(text) { if(isNaN(text)){ return 1; } else{ alert("Please enter a valid name. The only charachters
JavaScript types
JavaScript types  What are JavaScript types
javascript validation
javascript validation  validation of comparing dropdownlist and textbox in javascript
JavaScript and ECMAScript
JavaScript and ECMAScript  What?s relationship between JavaScript and ECMAScript
javascript doubt
javascript doubt  How to retrieving the values from Database by using javascript
JavaScript - JavaScript Tutorial
JavaScript Tutorials is one of the best Quick reference to the JavaScript. In this JavaScript reference you will find most of the things about java script. JavaScript tutorial is classified into sections with examples. This tutorial
JavaScript - JavaScript Tutorial
JavaScript Tutorials is one of the best Quick reference to the JavaScript. In this JavaScript reference you will find most of the things about java script. JavaScript tutorial is classified into sections with examples. This tutorial
Prototypes for JavaScript
Prototypes for JavaScript  What's Prototypes for JavaScript