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



Home Answers Viewqa JSP-Servlet problem of confirmation
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


gautamshetkar
problem of confirmation
2 Answer(s)      3 years and 8 months ago
Posted in : JSP-Servlet


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


Advertisement
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
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
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
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
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
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
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
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 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
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
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, like thanks n regards himanshu
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
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 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
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
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
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 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
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
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
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 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
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
Advertisements
 

 

 

DMCA.com