
sir,
I tried ur following code
<script language="javascript">
function deleteRecord(){
var doIt=confirm('Do you want to delete the record?');
if(doIt){
var f=document.form;
f.method="post";
f.action='../delete_sup?';
f.submit();
} else{
}
}</script>
I dont need to pass id as record is already diaplayed
and i used it in delete button like this
<center><input size="7" onclick="deleteRecord();"type="submit" value="Delete" name="insert" />
It shows confirm box but when i choose cancel it still submits the form.
Please help me.

print("code sample");
Ur Code
function deleteRecord(){ var doIt=confirm('Do you want to delete the record?'); if(doIt){ var f=document.myform; f.method="post"; f.action='../delete_sup?'; f.submit(); } else{ } }

Please post your code so that we can help you easily.

the values in textbox come by ajax after selecting id from dropdown
//this is my form and delete_sup is my servelet
<form method="post" id="myform" name="myform" action="delete_sup" >
<center>
<h3>Delete Supplier OR Edit Supplier</h3>
</center><br><br><br>
<font color=""> <center> <table border="0px" style="border-width: 2px; border-color:#4E387E;
border-style: solid;border-spacing: 6px" bgcolor="#CCFB5D">
<div id="mydiv"></div>
<tr>
<td>
Supplier ID
</td>
<td>
<select name="suplierid" onchange="showEmp(this.value);">
<option value="-1">Select</option>
<% Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con1 = DriverManager.getConnection("jdbc:mysql://localhost:3306/inventory", "root", "mca");
Statement stmt1 = con1.createStatement();
ResultSet rs2 = stmt1.executeQuery("Select s_id from supplier");
while (rs2.next()) {
String sup = rs2.getString(1);
%>
<option value="<%=sup%>"><%=sup%></option>
<% }%>
</select><br>
</td>
</tr>
<tr>
<td>Name:<font color="red">*</font></td><td><input type="text" name="name" id="name"value="" size="25"onkeypress="return ischarkey(event)"/></td>
</tr>
<tr>
<td>Address:<font color="red">*</font></td><td><textarea name="address" id="address"rows="4" cols="20"onkeypress="return ischarkey(event)">
</textarea></td>
</tr>
<tr>
<td>Pin code:</td><td> <input type="text" name="pin code" id="pin code"value="" size="7" onkeypress="return isNumberKey(event)"/></td>
<td>Landline No:<font color="red">*</font></td><td><input type="text" name="landline" id="landline"value="" size="15" onkeypress="return isNumberKey(event)"/></td>
<td>Fax No:</td><td><input type="text" name="fax" id="fax"value="" size="15" onkeypress="return isNumberKey(event)"/></td>
</tr>
<td>Mobile No:</td><td><input type="text" name="mobile" id="mobile"value="" size="15" onkeypress="return isNumberKey(event)"/></td>
<td>Email 1:<font color="red">*</font></td><td><input type="text" name="email1" id="email1"value="" size="20"/></td>
<td>Email 2:</td><td><input type="text" name="email2" id="email2"value="" size="20"/></td>
<tr>
</tr>
<tr>
<td colspan="6"><br>
<center><input onclick="deleteRecord();"type="submit" value="Delete" name="insert" /> <input size="15" type="submit" value="Edit" name="insert" /> <a href="Admin_main.jsp"><input type="button" value="Cancel" name="cancel" /></a>
</center><br>
<%String msg = request.getParameter("msg");
if (msg != null) {%>
<center><label><font color="red"><%=msg%></font></label></center>
<% }
%>
</td>
</tr>
</table></center></font>
<input type="hidden" name="username" value="<%= username%>" />
<input type="hidden" name="pass" value="<%= pass%>" />
</form>
//this is javascript function given by you
function deleteRecord(){
var doIt=confirm('Do you want to delete the record?');
if(doIt){
var f=document.form;
f.method="post";
f.action='../delete_sup?';
f.submit();
}
else{
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.