Question: javascript



Share on Google+Share on Google+

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
Java Spring Hibernate Struts Training Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java Java Example Codes and Tutorials in 2017 How do I read a large file quickly in Java? Is learning Java worthwhile? How to create first Java Program? Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include?


Advertisement null