Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


freena
jsp help
2 Answer(s)      4 years and 5 months ago
Posted in : JSP-Servlet


i want to add n remove rows dynamically and also want to add data in database in jsp ....

Advertisement
View Answers

July 30, 2010 at 11:07 AM


Hi Friend,

Try the following code:

1)table.jsp:

<HTML>
<HEAD>
<TITLE> Add/Remove dynamic rows in HTML table </TITLE>
<SCRIPT language="javascript">
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells[i].innerHTML;
newcell.childNodes[0].value = "";
newcell.childNodes[0].value = "";
}
}
function deleteRow()
{
var ptable = document.getElementById('dataTable');
var lastElement = ptable.rows.length;
if (lastElement > 1) ptable.deleteRow(lastElement - 1);
if(document.getElementById("psize").value>1)
{
document.getElementById("psize").value =
document.getElementById("psize").value-1;
}
}

</SCRIPT>
</HEAD>
<BODY>
<INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
<INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
<FORM method="post" action="insertTableData.jsp">
<input type="hidden" name="psize" id="psize">
<TABLE id="dataTable" width="350px" border="1">
<TR>
<TD><INPUT type="text" name="txt1"/></TD>
<TD><INPUT type="text" name="txt2"/></TD>
</TR>
</TABLE>
<INPUT type="submit" value="Insert">
</FORM>
</BODY>
</HTML>

2)insertTableData.jsp:

<%@page import="java.sql.*"%>
<%
String text1[]=request.getParameterValues("txt1");
String text2[]=request.getParameterValues("txt2");

for(int i=0;i<text1.length;i++){
System.out.println(text1[i]);
}
for(int i=0;i<text2.length;i++){
System.out.println(text2[i]);
}
try {

Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test";, "root", "root");
Statement st = conn.createStatement();
for(int i=0;i<text1.length;i++){
String name=text1[i];
String address=text2[i];
st.executeUpdate("insert into data(name,address) values('"+name+"','"+address+"')");
}
out.println("Record is inserted successfully");
}
catch(Exception e){
System.out.println(e);
}
%>

Thanks


July 30, 2010 at 11:35 AM


thaks a lot.....


Related Tutorials/Questions & Answers:
JSP help
JSP help  Hi i am using jsp,html and mysql. I am displaying one question & their 4 options per page. For that i have one label for question &... do this? Please Help
jsp help
jsp help  Hi i am doing my project in jsp.using netbeans 6 and mysql 5.0. and i managed to complete it. and now its submission time. but am confused... with it. so that my project can run independently in any server. plz help me. am so
Advertisements
jsp help - JSP-Servlet
jsp help  hai friends i am using videos,which will play on my webpage using flowplayer.my doubt is where will i store my videos whether in the database or in another local folder. please help me as soon as possible thanks
jsp help - JSP-Servlet
jsp help  In below code value got in text box using 'ID' Attribute ... I want to use that value in query to fetch related values in same page...://www.roseindia.net/jsp/comboSelect.shtml Thanks
jsp help - JSP-Servlet
jsp help  i want to add n remove rows dynamically and also want to add data in database in jsp ....  Hi Friend, Try the following code: 1)table.jsp: Add/Remove dynamic rows in HTML table function
jsp help - JSP-Servlet
jsp help  i got below code for dynamically add n delete row... but in my table there are 17 colum in 1 row..i want to add whole row with 17 cloum.. so which changes are required??? 1)table.jsp: Add/Remove dynamic
help me - JSP-Servlet
help me   how to open one compiled html file by clicking one button from jsp
Help on JSP - JDBC
Help on JSP  Sir I am makeing a project name Online reservation and Enquiry system. I had completed the front end design with the help of html,delete and search the database from the html file with the help of JSP.  hi
Need help on JAVA JSP
Need help on JAVA JSP  Hi, I have never worked on java and I have been given an assignment where I have to fix existing issues in the tool(created using JAVA JSP). e.g. Tool does not adjust with the resolution of the screen
help on project - JSP-Servlet
help on project  Need help on Java Project
Help on JSP and JDBC - JDBC
Help on JSP and JDBC  Retrieve data from Database in JSP and JDBC...;hi friend, jsp only for view , we should use for presentation don t combine databse code and jsp, it is not good approach,use separate class
please help in jsp - JSP-Servlet
please help in jsp  i have two Jsp's pages. on main.jsp have some... data. here some data of Jsp's. main.jsp... please help.  Hi Friend, Try
please help - JSP-Servlet
with others combox values. Here is JSP's files: display.jsp... To Year "> please help
Help needed in JSP
Help needed in JSP  Hi .. I want to Update the multiple values of database using checkboxes and want to set the session for selected checkboxes..? please answer if any one knows as soon as possible
help me to do it in jsp
help me to do it in jsp  if we click on a topic it should direct to another page in separate window i need to create a part of the web page which... to insert and update the topics via admin page. pls help me to do
Please Help - JSP-Servlet
Please Help  Respected Sir/Madam, I am R.Ragavendran.. Thanks for your response.. You told me that its difficult to handle the problem.. Ok,Let me try my hands on it.. The help i need is can u please tell me
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form which allows the user to enter a question, this question is then saved...;title>JSP Form</title> <style> </style>
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form which allows the user to enter a question, this question is then saved...;title>JSP Form</title> <style> </style>
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form which allows the user to enter a question, this question is then saved...;title>JSP Form</title> <style> </style>
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form which allows the user to enter a question, this question is then saved...;title>JSP Form</title> <style> </style>
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form which allows the user to enter a question, this question is then saved...;title>JSP Form</title> <style> </style>
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form which allows the user to enter a question, this question is then saved...;title>JSP Form</title> <style> </style>
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form which allows the user to enter a question, this question is then saved...;title>JSP Form</title> <style> </style>
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form which allows the user to enter a question, this question is then saved...;title>JSP Form</title> <style> </style>
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form which allows the user to enter a question, this question is then saved...;title>JSP Form</title> <style> </style>
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form which allows the user to enter a question, this question is then saved...;title>JSP Form</title> <style> </style>
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form which allows the user to enter a question, this question is then saved...;title>JSP Form</title> <style> </style>
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form which allows the user to enter a question, this question is then saved...;title>JSP Form</title> <style> </style>
Java and JSP help
Java and JSP help  I have a website, on my website i have made a form which allows the user to enter a question, this question is then saved...;title>JSP Form</title> <style> </style>
Help with javascript function - JSP-Servlet
Help with javascript function  I've got a button in a for loop.Each... properties of those clicked buttons to be transferred to the next jsp page... this task? ***Your help would very much appreciated
Programming Help URGENT - JSP-Servlet
Programming Help URGENT  Respected Sir/Madam, I am... TO ROSEINDIA TEAM< IF I GET THIS HELP IN TIME.... Thanks/Regards...://www.roseindia.net/jsp/implement-javascript-with-jsp.shtml Thanks
 

 

 

DMCA.com