我想要使用編輯和刪除按鈕來刪除一個帶有JSP頁面的數據庫記錄。我嘗試了下面的代碼。但只有第一個按鈕正在工作(無論我放在頂部),而第二個按鈕不起作用。任何人都可以幫助..?有兩個onclick事件的兩個按鈕不起作用
<%@ page import="java.sql.*" %>
<html>
<head>
<script language="javascript">
function edit(regno){
var f=document.form;
f.method="post";
f.action='edit.jsp?regno='+regno;
f.submit();
}
function delete(regno){
var f=document.form;
f.method="post";
f.action='delete.jsp?regno='+regno;
f.submit();
}
</script>
</head>
<body>
<form method="post" name="form">
<table border="1">
<tr><th>Name</th><th>Address</th><th>Edit</th><th>Delete</th></tr>
<%
Connection conn = null;
int sumcount=0;
Statement st;
try{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:mydb1");
String query = "select * from student";
st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
%>
<%
while(rs.next()){
%>
<tr>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><input type="button" name="delete" value="Delete"
onclick="delete(<%=rs.getString(1)%>);"> </td>
<td><input type="button" name="edit" value="Edit"
onclick="edit(<%=rs.getString(1)%>);"> </td>
</tr>
<%
}
%>
<%
}
catch(Exception e){
e.printStackTrace();
}
%>
</table>
</form>
</body>
</html>
向我們展示你到目前爲止嘗試過的嗎?在你的情況下,發佈'edit()'和'delete()'函數。還有你的商業邏輯。 –
對於您的信息,您需要編輯您的問題以發佈您的更新代碼。 –
嗨Vinoth,改變了問題..請看.. – user3190608