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



Home Answers Viewqa JSP-Servlet javascript for textbox or prompt using servlet
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


harini
javascript for textbox or prompt using servlet
1 Answer(s)      4 years and 6 months ago
Posted in : JSP-Servlet


Dear sir
I am writing script in servlet,so prompt() is not working here so please help me...In my project when a vendors want to delete the uploaded file ,if they are confirmed to delete the i have to take a reason for deleting a textbox as to come if press ok then delete the file then i have to store that reason in a data base so how to do in servlet.please help
me..

My code is as follows
out.println("function del(path,xxx){");
out.println(" var Cv = null;");
out.println(" Cv = confirm(\"Are you sure to delete the file?\");");
out.println(" if(Cv){");
out.println("if(path == \"detach\"){");
out.println(" var reason=prompt('Reason for deleting:','')");
out.println("document.attach.CatId.value=xxx;");
out.println("document.attach.action=\"../servlet/del_files\";");
out.println("document.attach.submit();")
out.println("}");
out.println("}");
out.println("}");

Thanks..

Advertisement
View Answers

July 15, 2010 at 4:01 PM


Hi Friend,

Try the following code:

1)Servlet.java:

import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Servlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException{
PrintWriter out = response.getWriter();
out.println("<html><head><script>function deleteRecord(id){var r=confirm('Are you confirm')");
out.println("if (r==true){var reason=prompt('Reason for deleting:')");
out.println("window.open('http://localhost:8080/examples/modified/deleteuser.jsp?id='+id+'&&reas='+reason,'mywindow','width=500, height=350,toolbar=no,resizable=yes,menubar=yes')");
out.println("}}</script></head>");
out.println("<form name='form'>");
out.println("<table border='1'>");
out.println("<tr><th>FirstName</th><th>LastName</th><th>Address</th><th>Email</th></tr>");
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String userName ="root";
String password="root";
int sumcount=0;
Statement st;
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db,userName,password);
String query = "select * from employee";
st = con.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next()){
out.println("<tr><td>"+rs.getString(2)+"</td><td>"+rs.getString(3)+"</td><td>"+rs.getString(4)+"</td><td>"+rs.getString(5)+"</td>");
out.println("<td><input type='button' name='edit' value='Delete' style='background-color:red;font-weight:bold;color:#ffffff;' onclick=\"deleteRecord('"+rs.getString(1)+"');\"></td></tr>");
}
}
catch (Exception e) {
e.printStackTrace();
}
out.println("</table>");
out.println("<form>");
out.println("</html>");
}
}

2)deleteuser.jsp:

<%@page language="java"%>
<%@page import="java.sql.*"%>
<%
String reason=request.getParameter("reas");
out.println("Reason is: "+reason);
String id=request.getParameter("id");
int no=Integer.parseInt(id);
int sumcount=0;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test";, "root", "root");
Statement st = conn.createStatement();
st.executeUpdate("DELETE FROM employee WHERE userid = '"+no+"'");
out.println("<br>Record is deleted successfully");
}
catch(Exception e){}
%>

Hope that it will be helpful for you.
Thanks


Related Tutorials/Questions & Answers:
javascript for textbox or prompt using servlet - JSP-Servlet
javascript for textbox or prompt using servlet  Dear sir I am writing script in servlet,so prompt() is not working here so please help me... ,if they are confirmed to delete the i have to take a reason for deleting a textbox as to come
javascript for textbox or prompt using servlet - JSP-Servlet
javascript for textbox or prompt using servlet  Dear sir, I am using a prompt(),when a delete is confirmed,its working fine ,but when a prompt is closed or cancel ,i have to remain in the same page but here it is going
Advertisements
javascript for prompt - JSP-Servlet
javascript for prompt  Dear sir, I have used prompt() for taking a reason while deleting using java script its working fine but prompt was coming at the top left so i want that prompt should come at middle so how to do
javascript for prompt - JSP-Servlet
javascript for prompt  Dear Sir, I am using a prompt() for taking... a prompt contains any special character or what.If contains a alert message has... then that prompt was not coming..So please tel me how to validate a prompt
javascript for prompt - JSP-Servlet
javascript for prompt  Dear sir, I am using prompt()for taking a reason from vendor . var reason=prompt('Reason for deleting:',''); Then i... an object ,so how to remove this script error.And also this prompt is coming
javascript for textbox - JSP-Servlet
javascript for textbox  Dear sir , How to write a javascript for a textbox ?.I am doing a delet operation.When i clik on a particular record... a javascript to do so ..Please help me sir... Thanks...  Hi Friend, Try
javascript for textbox - JSP-Servlet
javascript for textbox  Dear Sir, In my project if i use a var reason=prompt(\"Reason for deleting:\",\"\") in a javascript after confirm the delete option ,its not invoking the prompt()...So please help me.. Thanks
javascript for textbox - JSP-Servlet
javascript for textbox  Dear Sir , Thanks for posting an answer, its working fine .Sir how to get the text what we have entered in a prompt(reason... that value.I used the following code reason=prompt("Reason for deleting
javascript for textbox - JSP-Servlet
javascript for textbox  Dear sir, Thanks for your post,but when i write if(reason=="") i am getting a following error in eclipse i.e a red... written if(reason=="") in Scriptlets?You can write this code only in the javascript
using prompt
using prompt  how to use prompt
javascript prompt alert
javascript prompt alert   Sending a prompt alert using a JavaScript function
How to check text in textbox using JavaScript
How to check text in textbox using JavaScript  How to check text in textbox using JavaScript I have a form in HTML that contains text feilds... me.   JavaScript validation example to check text in textfeild <
prompt using
prompt using  I want examples to use prompt and how to move the item from the prompt to a cell in a table. thank you
Javascript generate textbox
Javascript generate textbox In this tutorial, you will learn how to generate a textbox on button click using javascript. Here is a javascript example... of textboxes. On clicking the button with respect to each textbox, it will give
passing textbox value from one page to another page using html n javascript
passing textbox value from one page to another page using html n... of variable at onclick event of button and also want to print it in textbox...)page2.html: <html> <script LANGUAGE="JavaScript"> function getParams
Prompt
into methods in the method asking for the input it uses a prompt command...) { System.out.print(**prompt** + ' '); return numberOfGrades } I don't undersant the prompt part
coding for horizontal menubar using using html or javascript - JSP-Servlet
coding for horizontal menubar using using html or javascript  hii friends, i wanted to implement horizontal menubar in my project tht wil open the links to diffrnt pages kindly help
how to get data using dropdownlist, textbox and search button in jsp
how to get data using dropdownlist, textbox and search button in jsp  Hi, I want to display data using jsp,javascript and mysql. My Q. is If i select...' in textbox and click on search button it should show me all the title names
Javascript change textbox background
Javascript change textbox background In this section, you will learn how to change the background of textbox. Here we have created a textbox and allowed the user to enter the valid name. If the entered name is 'roseindia
Set Textbox in PowerPoint Slide Using Java
Set Textbox in PowerPoint Slide Using Java       In this example we are going create textbox to set text in PowerPoint using java. In this example we are creating an object of 
How to create textbox on combo value selection using javacsript in jsp?
How to create textbox on combo value selection using javacsript in jsp?  dynamically create textbox on combo value selection. when select multiple values then create multiple textboxes
How to display on textbox using ObjectUtil class
How to display on textbox using ObjectUtil class       In this tutorial we will see how to display a text in textbox using ObjectUtil class. Here
Selecting value from autocomplete textbox using jquery in jsp
Selecting value from autocomplete textbox using jquery in jsp   hello Sir, I completed ur tutorial on autocompletion textbox from database using... not select the suggested values in the textbox,means on clicking particular field
How to insert dynamic textbox values into database using Java?
How to insert dynamic textbox values into database using Java?  Hi I am trying to insert dynamic textbox values to database, my jsp form have 2... these dynamic textbox values to database(Oracle 11g)...Please help me out. I have
populating textbox value from the database using onchange function,
populating textbox value from the database using onchange function,  hi, Everyone I have a problem regarding poulatinng the value in textbox after.... but the next textbox value is populated from database. plz help me guys
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database.  Hii Sir, Lots of thnx to ur reply .I went through both... of selecting value from autocomplete textbox using jquery in jsp from mysql database
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database.  Sir, Lots of thnx to ur reply .I went through both the tutorials... autocomplete textbox using jquery in jsp from mysql database. Kindly send me
How to insert data from a combobox and textbox values into DB using JSP?
How to insert data from a combobox and textbox values into DB using JSP?  hi, How to insert a comb-box and a text box values in to DB using JSP? @DB:student; @table:stu_info; Combobox values:(class1,class2,class3); textbox1
Command Prompt in UI
Command Prompt in UI  Hi One Help... Please go through. I want to develop like that using jsp/javascript but nothing is striking in mind... Please give some suggestions to design first Thanks in advance---- Vanchinathan.R
javascript error in IE - JSP-Servlet
javascript error in IE  Please Help me, I have an urgent requirement i.e. JavaScript prompt box is not working in IE. It Works firefox,safari... in the Internet Options->customlevel changes. How to do displayin the prompt box using
Date object using JavaScript
Date object using JavaScript  What's the Date object using JavaScript
 

 

 

DMCA.com