problem of confirmation

problem of confirmation

sir, I tried ur code but when i click on cancel it still submits

I dont need to pass id as record is already diaplayed using ajax and i used it in delete button like this

<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"  />&nbsp;&nbsp;<input size="15" type="submit" value="Edit" name="insert" />&nbsp;&nbsp;<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>

Javascript code whcish was given by you

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 help me, I m stuck. Thanks

View Answers

April 25, 2011 at 4:49 PM

Check this:

1)ajax.jsp:

<%@page import="java.sql.*"%>
<html>
<head>
<script type="text/javascript">
function showData(id){ 

xmlHttp=GetXmlHttpObject()
var url="getdata.jsp";
url=url+"?id="+id;
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged(){ 
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
    var showdata = xmlHttp.responseText; 
    var strar = showdata.split(":");
    document.getElementById("name").value= strar[1];
    document.getElementById("address").value= strar[2];
    document.getElementById("contactNo").value= strar[3];
    document.getElementById("email").value= strar[4];
    } 
}
function GetXmlHttpObject(){
var xmlHttp=null;
try {
  xmlHttp=new XMLHttpRequest();
 }
catch (e) {
 try  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
function confirmDelete(){
    var doIt=confirm('Do you want to delete the record?');
                if(doIt){
                    var f=document.employee;
                    f.method="post";
                    f.action='deleteRecord.jsp';
                    f.submit();
                }
                else{
                }
}

</script>
</head>
<body>
<form name="employee" >
<br><br>
<table >
<div id="mydiv"></div>
<tr><td><b>Select:</b></td><td><select name="id" onchange="showData(this.value);">
<option value="-1">--Select--</option>
   <%
   Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from employee ");
           while(rs.next()){
               %>
               <option value="<%=rs.getInt("id")%>"><%=rs.getInt("id")%></option>
               <%
           }
               %>
               </select></td></tr>

<tr><td><b>Name:</b></td><td><input  type="text" name="name" id="name" ></td></tr>
<tr><td ><b>Address:</b></td><td>
<input  type="text" name="address" id="address" ></td></tr>
<tr><td><b>ContactNo:</b></td><td>
<input  type="text" name="contactNo" id="contactNo" ></td></tr>
<tr><td><b>Email:</b></td><td>
<input  type="text" name="email" id="email" ></td></tr>
</table>
<input type="button" value="Delete" onclick="confirmDelete();">
</form>    
<table border="0" width="100%" align="center">
<br>
<br>
</table>
</body>
</html>

April 25, 2011 at 4:49 PM

continue..

2)getdata.jsp:

<%@ page import="java.sql.*" %> 
<%
int id = Integer.parseInt(request.getParameter("id"));
String data ="";
try{
           Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from employee where id="+id+"");
while(rs.next())
{
data =":"+rs.getString("name")+":"+rs.getString("address") + ":" + Integer.parseInt(rs.getString("contactNo"))+":"+rs.getString("email");
}
out.println(data);
System.out.println(data);
}
catch (Exception e) {
System.out.println(e);
}
%>

3)deleteRecord.jsp:

<%@ page import="java.sql.*" %> 
<%
int id = Integer.parseInt(request.getParameter("id"));
try{
           Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           int i=st.executeUpdate("delete from employee where id="+id+"");
           out.println("Record is deleted successfully");
           response.sendRedirect("ajax.jsp");
}
catch (Exception e) {
System.out.println(e);
}
%>









Related Tutorials/Questions & Answers:
problem of confirmation
problem of confirmation  sir, I tried ur code but when i click on cancel it still submits I dont need to pass id as record is already diaplayed using ajax and i used it in delete button like this <form method="post" id
Confirmation Mail
Confirmation Mail  hi, i need the code.when we sign up it will send the confirmation mail to the e-mail right.how to do that part.....and also help me whether the AJAX is better or PHP better for the front design
Advertisements
How to create a confirmation box?
How to create a confirmation box?  How to create a confirmation box
Need runescape 2007 gold but hate phone confirmation?
Need runescape 2007 gold but hate phone confirmation?  Do you think...? Now, Rs2sale.com solves this problem, you can buy cheapest rs 07 gold without any confirmation pay by paypal. 6% discount code for you: PPSALE
email confirmation - Hibernate
update. Firstly I am facing with problem to add or reading link or parameter... having a problem and visit to : http://www.roseindia.net/jsf/myfacesspring
Show Confirmation Dialog on Click the Command Link
Show Confirmation Dialog on Click the Command Link  How to show Confirmation Dialog when user Click the Command Link
ModuleNotFoundError: No module named 'django-generic-confirmation'
ModuleNotFoundError: No module named 'django-generic-confirmation'  ...: No module named 'django-generic-confirmation' How to remove the ModuleNotFoundError: No module named 'django-generic-confirmation' error? Thanks
ModuleNotFoundError: No module named 'django-generic-confirmation'
ModuleNotFoundError: No module named 'django-generic-confirmation'  ...: No module named 'django-generic-confirmation' How to remove the ModuleNotFoundError: No module named 'django-generic-confirmation' error? Thanks
ModuleNotFoundError: No module named 'django-simple-email-confirmation'
ModuleNotFoundError: No module named 'django-simple-email-confirmation' ...: ModuleNotFoundError: No module named 'django-simple-email-confirmation' How to remove the ModuleNotFoundError: No module named 'django-simple-email-confirmation'
ModuleNotFoundError: No module named 'django-user-action-confirmation'
ModuleNotFoundError: No module named 'django-user-action-confirmation' ...: ModuleNotFoundError: No module named 'django-user-action-confirmation' How to remove the ModuleNotFoundError: No module named 'django-user-action-confirmation' error
ModuleNotFoundError: No module named 'django-user-action-confirmation'
ModuleNotFoundError: No module named 'django-user-action-confirmation' ...: ModuleNotFoundError: No module named 'django-user-action-confirmation' How to remove the ModuleNotFoundError: No module named 'django-user-action-confirmation' error
ModuleNotFoundError: No module named 'openlabs_sale_confirmation_email'
ModuleNotFoundError: No module named 'openlabs_sale_confirmation_email' ...: ModuleNotFoundError: No module named 'openlabs_sale_confirmation_email' How to remove the ModuleNotFoundError: No module named 'openlabs_sale_confirmation_email'
ModuleNotFoundError: No module named 'pinax-phone-confirmation'
ModuleNotFoundError: No module named 'pinax-phone-confirmation'  Hi...: No module named 'pinax-phone-confirmation' How to remove the ModuleNotFoundError: No module named 'pinax-phone-confirmation' error? Thanks  
ModuleNotFoundError: No module named 'django_confirmation_mixin'
ModuleNotFoundError: No module named 'django_confirmation_mixin'  Hi...: No module named 'django_confirmation_mixin' How to remove the ModuleNotFoundError: No module named 'django_confirmation_mixin' error? Thanks  
ModuleNotFoundError: No module named 'django-email-confirmation'
ModuleNotFoundError: No module named 'django-email-confirmation'  Hi...: No module named 'django-email-confirmation' How to remove the ModuleNotFoundError: No module named 'django-email-confirmation' error? Thanks  
ModuleNotFoundError: No module named 'django-generic-confirmation'
ModuleNotFoundError: No module named 'django-generic-confirmation'  ...: No module named 'django-generic-confirmation' How to remove the ModuleNotFoundError: No module named 'django-generic-confirmation' error? Thanks
ModuleNotFoundError: No module named 'django-mail_confirmation'
ModuleNotFoundError: No module named 'django-mail_confirmation'  Hi...: No module named 'django-mail_confirmation' How to remove the ModuleNotFoundError: No module named 'django-mail_confirmation' error? Thanks  
ModuleNotFoundError: No module named 'django_phone_confirmation'
ModuleNotFoundError: No module named 'django_phone_confirmation'  Hi...: No module named 'django_phone_confirmation' How to remove the ModuleNotFoundError: No module named 'django_phone_confirmation' error? Thanks  
ModuleNotFoundError: No module named 'django-Rest-phonenumber-confirmation'
ModuleNotFoundError: No module named 'django-Rest-phonenumber-confirmation...: ModuleNotFoundError: No module named 'django-Rest-phonenumber-confirmation' How...-confirmation' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'django-simple-email-confirmation'
ModuleNotFoundError: No module named 'django-simple-email-confirmation' ...: ModuleNotFoundError: No module named 'django-simple-email-confirmation' How to remove the ModuleNotFoundError: No module named 'django-simple-email-confirmation'
ModuleNotFoundError: No module named 'django-user-action-confirmation'
ModuleNotFoundError: No module named 'django-user-action-confirmation' ...: ModuleNotFoundError: No module named 'django-user-action-confirmation' How to remove the ModuleNotFoundError: No module named 'django-user-action-confirmation' error
ModuleNotFoundError: No module named 'fio_sale_confirmation_email'
ModuleNotFoundError: No module named 'fio_sale_confirmation_email'  ...: No module named 'fio_sale_confirmation_email' How to remove the ModuleNotFoundError: No module named 'fio_sale_confirmation_email' error? Thanks
Closing any kind of browser window without confirmation using javascript
Closing any kind of browser window without confirmation using javascript  Here is my requirement, I have to close a browser window on onload event... help me in resolving this problem. It should support any kind of browser and any
should close the browser with user confirmation in javascript - Java Beginners
should close the browser with user confirmation in javascript  Hi, I need to close the browser with the user confirmation. If the user accept olny... this will help u.if not then again post the problem. Detecting browser
How to force cp to overwrite without confirmation
command? How to force cp to overwrite without confirmation? Thanks   
closing the internet explorer window of any version without confirmation using javascript
closing the internet explorer window of any version without confirmation using javascript  Hi all, Here is my requirement, I have to close microsoft internet explorer window on onload event without confirmation. It should
problem in onlinetest...
problem in onlinetest...  hi, my code getting the problem is ,when user leave a question then the server puts error... pls help me
problem in validation
problem in validation  sir/madam, i m using struts-1.3.10. i m getting a problem my properties file is not found.... while i hav configuired it in struts-config.xml file, likeADS_TO_REPLACE_1 thanks n regards himanshu
javascript problem
javascript problem  hi guys My problem is that I am using radio button for yes or no but i want to do that if I press yes button then enter... enter please help me this problem
how to use confirmation alert box before delete in jsp?
how to use confirmation alert box before delete in jsp?  I use submit button.I want alert box before deleting data.   1)application.jsp: <%@ page import="java.sql.*" %> <html> <head> <script
problem on strings
problem on strings  in string1 "123456 ABC DEF...",IN string2 "raveen". iwant to add string2 after 123456 in the first string based on index number.i need logic for this with out using StringBuffer concept. Thanks in advanace
Problem with loginbean.jsp
Problem with loginbean.jsp  http://www.roseindia.net/jsp/loginbean.shtml - I am getting an error in loginbean.jsp.There is some error regarding .What is hello in this? Also in this example how
compilation problem
compilation problem  struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation problem that package open symphony doesnot... havenot set the build path.if this is the problem then tell me how to set
compilation problem
compilation problem  struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation problem that package open symphony doesnot... havenot set the build path.if this is the problem then tell me how to set
Problem with cookies
Problem with cookies  Hello All, i need jsp code for RememberMe module of login. i am facing problem with cookies. so please if any one could guide me please help and provide mme the exact code.   Please visit
problem with package
problem with package  Dear sir, i have created one java file with package com.net; and i compiled the program.it showing the .class file in " net" folder.The problem is i want to use that .class file in some other
Oracle9i Problem
Oracle9i Problem  Hi I have a problem in Oracle9i .I have... the table what i created .But after closing the SQL+ ,the problem started.When i... .....;.it is saying no rows are selected.Why the problem arised in not getting the data that i
problem with session.invalidate()
problem with session.invalidate()  i stuck by a line with "session.invalidate()", after user logout also by pressing the back button of the browser user is still able to navigate to his home page and able to view the session
JScrollBar Problem...
JScrollBar Problem...  Hello Sir/mam, Can i know how to use JScrollBar to JFrame without adding any JPanel to it.. i want to add JScrollBar Directly to JFrame... Please Provide me Simple Example so i can understand
problem on php
problem on php   l have five tables and build them as forms and link between them php and database and i want to build query between them plz help me soon   PHP MySQL Tutorials
URL problem
URL problem  Hi. I have created a webpage for my project website. in that i have used frameset to split the page. Now if i click any link in the page its navigating to the another page. but the problem is here in the url its
Is AI a problem?
Is AI a problem?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: Is AI a problem? Try... "Is AI a problem?". Also tell me which is the good training courses
Skyline Problem
is the line tracing the largest y value from any rectangle in S The Problem: Write.... Your method should solve the problem three different ways; each solution
Problem in Array
Problem in Array  Hi, Can you help me with this problem? Run a program that check if the input string contains equal number of A's and B's. Hoping for your answer.Thank you.   Here is an example that check
problem
Problem
Problem
problem
problem
PROBLEM IDENTIFICATION
PROBLEM IDENTIFICATION  class MOrders { int nooforders; // Data members of the class public int getorder() { nooforders = 500; } public void displayorders() { System.out.println("The number of orders to be delivered

Ads