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



Home Answers Viewqa JSP-Servlet 17283-how-to-make-enable how to make enable/disable textbox in while(rs.next)

Have Programming Question? Ask it here!
 
 
 


Tay Hock Lye
how to make enable/disable textbox in while(rs.next)
1 Answer(s)      3 years and a month ago
Posted in : JSP-Servlet


Hi, I'm trying to enable/disable the textbox in the while loop. It works but when i want to update my data, the data are not updated correctly. When i remove the enable/disable function,the data are updated correctly. Is my javascript wrong? How do i correct it? Please help. Thank you. (only the update part is wrong)

JSP: editDepartment.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
</style>
<script language="javascript" type="text/javascript">
function enable_text(status)
{
    status=!status;
    deptName=document.updateDepartment.elements['updateDeptName'];
    HOD=document.updateDepartment.elements['updateHOD'];
    for (i=0;i<deptName.length;i++)
    {
        if ( document.updateDepartment.others[i].checked != status )
            {
        deptName[i].disabled = status;
        HOD[i].disabled = status;
            }
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body onload='disable_text(false)'>
<form name="addDepartment" action="AddDepartment">Add new
department : <br>
Department name : <input type="text" name="deptTxt" /> <br>
HOD name : <input type="text" name="HODTxt" /> <br>
<input type="submit" value="Add" /></form>
<form name="deleteDepartment" action="DeleteDepartment"><br>
<br>
Delete department : <br>
    <%
        Connection con = null;
        try {
            int row=1;
            Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
            con = DriverManager.getConnection(
                    "jdbc:oracle:thin:@localhost:1521:XE", "tay", "tay");
            Statement stmt = con.createStatement();
            ResultSet rs = stmt
                    .executeQuery("SELECT * FROM DEPARTMENT ORDER BY DEPARTMENT.DEPTNAME");
            out.println("<table id=delDept>");
            out.println("<tr>");
            out.println("<td>Delete<td>deptID<td>deptName<td>HOD");
            out.println("</tr>");
            while (rs.next()) {
                out.println("<td><input type='checkbox' name='chk' value='"+rs.getString("DEPTID")+"'>");
                out.println("<td>"+rs.getString("DEPTID"));
                out.println("<td>"+rs.getString("DEPTNAME"));
                out.println("<td>"+rs.getString("HOD"));
                out.println("</tr>");
                row = row + 1;
            }
            out.println("</table>");
            out.println("<input type=hidden name=counterloop value='"
                    + (row-1) + "'>");
            stmt.close();
            rs.close();
            //con.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    %>
<br>
<input type="submit" value="Delete" />
</form>
<form name="updateDepartment" action="UpdateDepartment">
<br><br>
Update department : <br>
    <%
        try {
            int row2=1;
            Statement stmt1 = con.createStatement();
            ResultSet rs1 = stmt1
                    .executeQuery("SELECT * FROM DEPARTMENT ORDER BY DEPARTMENT.DEPTNAME");
            out.println("<table id=updDept>");
            out.println("<tr>");
            out.println("<td>Select<td>deptID<td>deptName<td>HOD");
            out.println("</tr>");
            while (rs1.next()) {
                out.println("<tr>");
                out.println("<td><input type='checkbox' name='others' onclick='enable_text(this.checked)'>");
                //out.println("<td><input type='checkbox' name='others'>");
                out.println("<td><input type=hidden name=updateDeptID value='"+rs1.getString("DEPTID")+"'><input type=text name=updateDeptID disabled='true' value='"+rs1.getString("DEPTID")+"'>");
                out.println("<td><input type=text name=updateDeptName disabled='true' value='"+ rs1.getString("DEPTNAME")+"'>");
                out.println("<td><input type=text name=updateHOD disabled='true' value='"+rs1.getString("HOD")+"'>");
                out.println("</tr>");
                row2=row2+1;
            }
            out.println("</table>");
            out.println("<input type=hidden name=counterloop2 value='"+ (row2-1) + "'>");
            stmt1.close();
            rs1.close();
            con.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    %>
<br>
<input type="submit" value="Update" />
</form>
</body>
</html>

servlet: UpdateDepartment.java

package testpackage;

import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement;

import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;

/** * Servlet implementation class UpdateDepartment */ public class UpdateDepartment extends HttpServlet { private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String deptID[] = request.getParameterValues("updateDeptID");
    String deptName[] = request.getParameterValues("updateDeptName");
    String HOD[] = request.getParameterValues("updateHOD");
    Integer row = Integer.parseInt(request.getParameter("counterloop2"));
    System.out.println(row);
    Connection con = null;

    //if (deptID != null && deptID.length != 0)
    //{
    for(int i=0;i<row;i++)
    {   
    try {
        System.out.println(deptID[i]);  
        System.out.println(deptName[i]);    
        System.out.println(HOD[i]); 
        Class.forName("oracle.jdbc.driver.OracleDriver")
            .newInstance();
            con = DriverManager
            .getConnection(
                    "jdbc:oracle:thin:@localhost:1521:XE",
                    "tay", "tay");

            Statement stmt = con.createStatement();
            stmt.executeUpdate("UPDATE DEPARTMENT SET DEPTNAME='"+deptName[i] +"', HOD='"+HOD[i]+"' WHERE DEPTID='"+ deptID[i]+"'");
            con.close();
            }
    catch (Exception e) {
            System.out.println(e);
        }

}
//}
    response.sendRedirect("editDepartment.jsp");
}

}


Advertisement
View Answers

March 10, 2011 at 4:15 PM


JSP edit application:

1)editapplication.jsp:

<%@ page import="java.sql.*" %>
<html>
<script>
function enable_text(){
    var i=0;
    deptName=document.form.elements['name'];
    HOD=document.form.elements['address'];
    for (i=0;i<deptName.length;i++)  {
        if(document.form.check[i].checked){
        deptName[i].disabled = true;
        HOD[i].disabled = true;
            }
}
}
</script>
<form name="form"  method="post" action="retcheck.jsp">
 <table border="1">
<tr><th></th><th>Name</th><th>Address</th></tr>
<%
int i=0;
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String userName ="root";
String password="root";

int sumcount=0;
Statement st;
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db,userName,password);
String query = "select * from data";
st = con.createStatement();
ResultSet rs = st.executeQuery(query);
%>
<%
while(rs.next()){
%>
<tr><td><input type="checkbox" value="<%= rs.getString("id")%>"  onclick='enable_text()' name="check">
<td><input type="text" name="name" value="<%=rs.getString("name")%>"></td>
<td><input type="text" name="address" value="<%=rs.getString("address")%>"></td>
</tr>
<%
}
%>
<%
}
catch(Exception e){
e.printStackTrace();
}
%>
</table>
<input type="submit" value="Edit">
</form>
</html>

2)retcheck.jsp:

<%@ page import="java.sql.*" %>

<%
String id[]=request.getParameterValues("check");
%>
<form name="form" method=post action="up.jsp">
<table border=1>
<tr><th></th><th>Name</th><th>Address</th></tr>
<%
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
ResultSet rs = null;
Statement st=null;
st=conn.createStatement();
for(int a=0;a<id.length;a++){
rs = st.executeQuery("select * from data where id='"+id[a]+"'");
while(rs.next()){ 
    %>
<tr>
<td><input type="hidden" name="id" value="<%=rs.getString("id")%>" > </td>
    <td><input type="text" name="name" value="<%=rs.getString("name")%>"></td>
    <td><input type="text" name="address" value="<%=rs.getString("address")%>"></td></tr>
      <%
}
}
%>
</table>
<input type="submit" value="update">
</form>

3)up.jsp:

<%@ page import="java.sql.*" %>
<%
String id[]=request.getParameterValues("id");
String name[]=request.getParameterValues("name");
String add[]=request.getParameterValues("address");
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");

Statement st=null;
st=conn.createStatement();
for(int i=0;i<id.length;i++){
st.executeUpdate("update data set  name='"+name[i]+"',address='"+add[i]+"' where id='"+id[i]+"'");
out.println("Data is updated successfully");
}
response.sendRedirect("editapplication.jsp");
%>


Related Tutorials/Questions & Answers:
how to make enable/disable textbox in while(rs.next)
how to make enable/disable textbox in while(rs.next)  Hi, I'm trying to enable/disable the textbox in the while loop. It works but when i want.../disable function,the data are updated correctly. Is my javascript wrong? How do i
how to make enable/disable textbox in while(rs.next)
how to make enable/disable textbox in while(rs.next)  Hi, I'm trying to enable/disable the textbox in the while loop. It works but when i want.../disable function,the data are updated correctly. Is my javascript wrong? How do i
Advertisements
how to enable and disable a input type in jsp - JSP-Servlet
how to enable and disable a input type in jsp  how to disable the input type and enable based on some input in the input type   Hi Friend, Try the following code: function function1(){ var n
enable disable checkbox in javascript
enable disable checkbox in javascript  How to enable disable checkbox in javascript
Enable and Disable Tab in Java
Enable and Disable Tab in Java       In this section you will learn how to enable... number. To enable or disable any tab you can use the setEnabledAt(int index
enable disable table
enable disable table  hi I have table with 3 columns if i click one column the other 2 column should disable pls can anyboby help me
Task manager enable and disable thru java
Task manager enable and disable thru java  I would like to know, how to enable and disable task manager using java. Kindly, please Let me know
Jsp code to enable and disable certain links using jsp code - Java Beginners
Jsp code to enable and disable certain links using jsp code  Hi... have to enable/disable a link.I need a code to do that. Thanks in advance... but with only a certain links only visible and enabled. now my doubt is how can i
How to show data from database in textbox in jsp
How to show data from database in textbox in jsp   How to show data from database in textbox in jsp   Here is an example that retrieve... countryname LIKE '"+name+"%'"); while(rs.next()){ buffer=buffer
JTree Multiple Selection
Enable and Disable Multiple Selections in a JTree Component       In this section, you will learn how to enable and disable the multiple selections in a JTree
How to check text in textbox using JavaScript
How to check text in textbox using JavaScript  How to check text in textbox using JavaScript I have a form in HTML that contains text feilds and a submit button. The main purpose of this form is to take input from user. My
How to display current date in textbox - Date Calendar
How to display current date in textbox  Hi guys, I'm really need your...;% } This is my problem: I want to display current date in textbox... show in textbox. Please help me to solve that problem, I will wait your answer
How to create textbox on combo value selection using javacsript in jsp?
How to create textbox on combo value selection using javacsript in jsp?  dynamically create textbox on combo value selection. when select multiple values then create multiple textboxes
How to display on textbox using ObjectUtil class
How to display on textbox using ObjectUtil class       In this tutorial we will see how to display a text in textbox using ObjectUtil class. Here
how to display textbox value based on selected option value?
how to display textbox value based on selected option value?  Hi,I have some problem. I use jsp and ajax. first select: 1 second select:2 based...("<th>Time</th></tr>"); while(rs.next()){ data
How to insert dynamic textbox values into database using Java?
How to insert dynamic textbox values into database using Java?  Hi I am trying to insert dynamic textbox values to database, my jsp form have 2... these dynamic textbox values to database(Oracle 11g)...Please help me out. I have
how make ID - Ajax
how make ID  how make a ID in eyeball chat
How to make elements invisible ?
How to make elements invisible ?   How to make elements invisible
how to make this pattern???
how to make this pattern???  how to make following pattern in javascript
how to get the values from dynamically generated textbox in java?
how to get the values from dynamically generated textbox in java?  I... textbox corresponding to the data. I want to get data from textboxes(generated as per the retrieved data) and I want to store textbox values into the two table
how to get data using dropdownlist, textbox and search button in jsp
how to get data using dropdownlist, textbox and search button in jsp  Hi, I want to display data using jsp,javascript and mysql. My Q. is If i select...' in textbox and click on search button it should show me all the title names
how to make exampage in jsp ?
how to make exampage in jsp ?  how to make a online exam page in jsp and servelet
How to insert data from a combobox and textbox values into DB using JSP?
How to insert data from a combobox and textbox values into DB using JSP?  hi, How to insert a comb-box and a text box values in to DB using JSP? @DB:student; @table:stu_info; Combobox values:(class1,class2,class3); textbox1
HOW TO DISPLAY ID IN TEXTBOX BASED ON COMBOBOX SELECTION IN A SAME PAGE
HOW TO DISPLAY ID IN TEXTBOX BASED ON COMBOBOX SELECTION IN A SAME PAGE  Dear sir, Am having one table called rolemaster. In that there are 2 fields... is how to get Roleid in textbox when i select Role_name from combobox in a same
How to write a loop and a while loop
How to write a loop and a while loop  How do I write a 1 loop and a 1 while loop for the example code: public boolean isTheFirstOneBigger (int num1, int num2) { if (num1 > num2) { return true
showing the information of database in textbox
showing the information of database in textbox  how to make a information of a database make appear to the user in the textbox
how to make a program on array
how to make a program on array  When you make a program on array that the element will move downward and upward and when you input twice 0 then thats the time that it will not move. pls. give me a formula...tnx
how to text send from list to textbox - Swing AWT
how to text send from list to textbox  dear sir/madam I whant to send text from list to textbox. plz give me solution for this problem.   Hi friend, Plz explain the problem in details to solve it and specify
How to make selectOneMenu scrollable
How to make selectOneMenu scrollable  how to make the selectOneMenu scrollable? I have around 20 values in drop down and i want the scrollable functionality after 5 values. Kindly reply as soon as possible. Thanks Shikha
how to make employee i card
how to make employee i card  hello friends can anyone help me.. I have to make a project to make Identity card for employees...but i am facing..."; ResultSet rs = stmt.executeQuery(strQuery); while(rs.next()){ %>
how to make paging with function ?
how to make paging with function ?  how to make paging with function ?   //this page is display.php <?php</p> $con=mysql_connect... name user password gender e-mailid mobile no image edit delete "; while($row
how make excel
how make excel  how make excel spreadsheet IN JAVA. please send this code argently   Hello Friend, Try the following code: import java.io.*; import org.apache.poi.hssf.usermodel.HSSFSheet; import
How to automatically change the value of the textbox based on the dropdown list?
How to automatically change the value of the textbox based on the dropdown list?  I want to know how to automatically change the value of price..._stat!='Archived' order by item_name"); while(rst2.next
how to make multiple rectangles
how to make multiple rectangles  I,m a beginner , m sorry if the question is really simple i have an array list.I want to print the contents...(JFrame.EXIT_ON_CLOSE); //Set JFrame size setSize(400,400); //Make JFrame
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO..."); System.out.println("| q. Quit"); question = console.next().charAt(0... 'l': CheckEmptyList(); case 'q': Quit(); case 'Q
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO..."); System.out.println("| q. Quit"); question = console.next().charAt(0... 'l': CheckEmptyList(); case 'q': Quit(); case 'Q
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO..."); System.out.println("| q. Quit"); question = console.next().charAt(0... 'l': CheckEmptyList(); case 'q': Quit(); case 'Q
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO..."); System.out.println("| q. Quit"); question = console.next().charAt(0... 'l': CheckEmptyList(); case 'q': Quit(); case 'Q
how to retreive values from MS Access Database based on the values entered in textbox values in jsp file
* from item where itemid='"+id+"'"); while(rs.next()) { data = ":" + rs.getString...how to retreive values from MS Access Database based on the values entered in textbox values in jsp file  Hi am new to java. i need to create
Javascript change textbox background
Javascript change textbox background In this section, you will learn how to change the background of textbox. Here we have created a textbox and allowed the user to enter the valid name. If the entered name is 'roseindia
how to make a field left justification
how to make a field left justification  how to make a field left justification.need code.thanks in advance
how to make a label left alignment?
how to make a label left alignment?  how to make a label left alignment
How to make a chain, make a chain, chain
How to make a chain       To learn how to design a chain in the photoshop has become so easy by this example, it has some important instruction to make it so follow
How To get DgroupId while using maven.
How To get DgroupId while using maven.  Hello everyone, I read... it and it is working, but when i want to make other project for speech to text converter ,i can't find the right "DgroupId", also i can't get how to make
how to make paging with class and ajax
how to make paging with class and ajax  paging with class and ajax
How to make bubbles, make bubbles, bubbles
How to make bubbles      ... to make it easily to draw. New File: First take colored background file. Draw... Overlay, use same both settings as given below. Duplicate: Now make
How to make directory in java
Description: This example demonstrate how to create a directory at specified path. Code: import java.io.File; public ... is that it will make a dir at root directory of C drive
How to make a transparent text
How to make a transparent text Learn how to make a transparent...) and make formatting as looking here. Write Text: Now write your text as you like. I have written here "Text". After writing text make copy (Ctr
How to make halo effect
How to make halo effect       Now get ready to learn a simple way to make a halo effect on the picture, follow to make it. Take a picture: Capture any picture to give
How to make a bone, make a bone, a bone
How to make a bone       This example bone design example, It is very easy. If you are looking for, please follow now. New File: Create a new file. Rounded rectangle
 

 

 

DMCA.com