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



Home Answers Viewqa JSP-Servlet javascript for textbox
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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


Dear sir ,
How to write a javascript for a textbox ?.I am doing a delet operation.When i clik on a particular record that record should be deleted before deleting it an alert message is shown ,if ok then deleting a record.But now i want when a user clik on ok for deleting then a text box to come and where we have to write a reason for deleting ,after entering a reason click on ok then record should be deleted so how to write a javascript to do so ..Please help me sir...
Thanks...

Advertisement
View Answers

July 13, 2010 at 3:06 PM


Hi Friend,

Try the following code:

1)user.jsp:

<%@ page import="java.sql.*" %>
<html>
<head>
<script language="javascript">
function deleteRecord(id){
var r=confirm("Are you confirm");
if (r==true)
{
var reason=prompt("Reason for deleting:","");
if(reason==""){
}else{
window.open('http://localhost:8080/examples/jsp/deleteuser.jsp?id='+id,'mywindow','width=500, height=350,toolbar=no,resizable=yes,menubar=yes');
}
}
}
</script>
</head>
<body>

<br><br>
<table border="1">
<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()){
%>
<tr><td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
<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();
}
%>
</table>
</form>
</body>
</html>

2)deleteuser.jsp:

<%@page language="java"%>
<%@page import="java.sql.*"%>
<%
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("Record is deleted successfully");
}
catch(Exception e){}
%>

Thanks


Related Tutorials/Questions & Answers:
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
Advertisements
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
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).I need that reason to be displayed one next delete.jsp page so how to get
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
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 <
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
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
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
JAVASCRIPT
JAVASCRIPT  I have one textbox and I want to validate that it must start with number(1-0). can anyone tell me a javascript for that ? thanks in advance
javascript
javascript  hi, I was actually working on to calculate the number of days between two dates of yyyy-mm-dd format using javascript, and when i click on button then number of days should be display in textbox
javascript validation
javascript validation  validation of comparing dropdownlist and textbox in javascript
date in textbox on page load
date in textbox on page load   i want to insret the current date in textbox but this code dosen't work and the value of text box will be blank <script type="text/javascript"> function addDate
Getting mysql table in textbox
Getting mysql table in textbox  how to get mysql table values into textbox in java using ajax and servlets
showing the information of database in textbox
showing the information of database in textbox  how to make a information of a database make appear to the user in the textbox
Dynamically adding textbox and labels
Dynamically adding textbox and labels  Sir, In my application I want to insert texbox and labels dynamically and want to insert database field value in that generated label. Plz help me, Thanks in advance
display data from database in textbox when id entered in textbox
display data from database in textbox when id entered in textbox  i wanted to enter data in textbox .depending on entered data in textbox data from database should be displayed dynamically in textbox
retaining textbox values
retaining textbox values  i have a calculator program, when i press a button the value displays but disappears when i press another button so how can i keep values to display when i press multiple buttons
listbox and textbox validations
listbox and textbox validations  hi, any one please tell me how to set validations for listbox and textboxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
Sql Server 2008 with textbox
Sql Server 2008 with textbox  **Hi, I tried to insert into DB using textbox in a form using vb by visual studio 2010 but its always catch an error [Cannot open database "4" requested by the login. The login failed. Login failed
JavaScript
JavaScript  clone JavaScript
Dynamically hide textbox
. AVOID PAGE REDIRECTING jsp+servlet+oracle+javascript I am using
Ajax drop down and textbox
. <html> <head> <script language="javascript" type="text/javascript"> var xmlHttp var xmlHttp function
javascript
javascript  javascript code to dynamically add table on button click.../javascript/javascriptexamples/javascript-add-row-dynamically.shtml http://www.roseindia.net/javascript/javascript-add-row-to-table.shtml http://www.roseindia.net
Javascript
Javascript  How validations are done using javascript ,with example? and interview questions on javASCRIPT
javaScript
javaScript  How to open a browser window that cannot be resized? (HTML + Javascript
javascript
javascript  write a program to display implement about browsers using javascript
javascript
javascript  Hi deepak, how to write form validation on javascript
JavaScript
JavaScript  how to get full path of a file type in javascript
JavaScript
should use JavaScript? Thanks   Hi, JavaScript is scripting language that runs on browser. You have to embed JavaScript in HTML page. Please see JavaScript tutorial. Thanks
 

 

 

DMCA.com