Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This jsp calls deleteData1.java(servlet) when delete button is clicked and deletion was supposed to perform.I couldn't find out what is wrong in the function deleteData(id) when the button is clicked


XML
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.*;" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>

<script>

function deleteData(id){
    var xmlhttp;
    if(windows.XMLHttpRequest){
        xmlhttp = new XMLHttpRequest();
    }
    else{
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function(){
        document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
    }
    xmlhttp.open("GET","http://localhost:8080/First/deleteData1?id="+id, true);
    xmlhttp.send(null);
}



</script>

</head>
<body>
<br>
<table align="center">
 </table>
<br>

 <table border='1' width='300' cellpadding='1' cellspacing='0'>
    <tr><td colspan=6 align="center"></td></tr>
  <tr>
     <td>Id</td><td>Name</td><td>Department</td><td>Password</td>
     <td>Edit</td><td>Delete</td>
  </tr>

    <%

    List Li = new ArrayList();
    Iterator  lr;

    if(request.getAttribute("userList")!=null && request.getAttribute("userList")!="")
    {
        List userList =  (ArrayList)request.getAttribute("userList");
        Iterator itr = userList.iterator();

        while(itr.hasNext())
        {

            Li = (ArrayList)itr.next();
            lr = Li.iterator();
            Integer id = (Integer)lr.next();
            String name = (String)lr.next();
            String department = (String)lr.next();
            String password = (String)lr.next();

            %>
            <tr>
            <td><%=id%></td>
            <td><%=name%></td>
            <td><%=department%></td>
            <td><%=password%></td>
            <td><input type="button" name="edit" value="edit" onclick="editData(<%=id%>);" ></td>
                <td><input type="button" name="delete" value="Delete" onclick="deleteData(<%=id%>);"></td>
            </tr>
        <%
        }
    }
    %>
   }

  </table>
  <div id="mydiv"></div>
</body>
</html>
Posted
Comments
François Wahl 12-Aug-14 8:10am    
Are there any errors visible in your debugger console?
Snesh Prajapati 12-Aug-14 8:18am    
Did you check that call is reaching to deleteData and deleteData1 function ?
Member 10646081 12-Aug-14 9:39am    
No, there isn't any error in the console.The database is being show.But when i click the delete button, nothing is happening
thatraja 2-Sep-14 9:26am    
share the code for deleteData1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900