Javascript & jsp

Javascript & jsp

Dear Sir,

I have a table which has records relating to student name,roll no,sex,subject.address. I have a dropdown list which has all the roll numbers of the students in the database.How can i populate the text box like name,class,sex after selecting a roll number from the dropdown.It will populate automatically after selecting a roll number from the dropdown. It is urgent.Pliz help.

regards

View Answers

April 12, 2011 at 11:20 AM

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;
}
</script>
</head>
<body>
<form name="employee">
<br><br>
<table >
<div id="mydiv"></div>
<tr><td><b>Select:</b></td><td><select onchange="showData(this.value);">
   <%
   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>
</form>    
<table border="0" width="100%" align="center">
<br>
<br>
</table>
</body>
</html>

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);
}
%>









Related Tutorials/Questions & Answers:
Javascript & jsp
Javascript & jsp  Dear Sir, Thanks a ton for all your answers throughout.I asked this question long ago.This time i nedd it very urgent.I think it might be a short solution.How can i get the navigation link whilr traversing
Javascript & jsp
Javascript & jsp  Dear Sir, Thanks a ton for all your answers throughout.I asked this question long ago.This time i nedd it very urgent.I think it might be a short solution.How can i get the navigation link whilr traversing
Advertisements
Javascript & jsp
Javascript & jsp  Dear Sir, Thanks a ton for all your answers throughout.I asked this question long ago.This time i nedd it very urgent.I think it might be a short solution.How can i get the navigation link whilr traversing
jsp /javascript
jsp /javascript  Hii.. I have to design one registration page in java that looks like REGISTER USERNAME (here i have to check whether username already exists in database) EMAIL ADDRESS (here i have to check
jsp /javascript
jsp /javascript  Hii.. I have to design one registration page in java that looks like REGISTER USERNAME (here i have to check whether username already exists in database) EMAIL ADDRESS (here i have to check
Javascript & jsp
Javascript & jsp  Dear Sir, I have a table which has records relating to student name,roll no,sex,subject.address. I have a dropdown list which has...*"%> <html> <head> <script type="text/javascript"> function
jsp or javascript - Java Beginners
jsp or javascript  hello sir can i run sql query in javascript
jsp,javascript - JSP-Servlet
jsp,javascript   Hi, I want to retrieve record and move it. Can any body tell me what is the problem with this code Deparment function update(s) { alert(s); if (s==0) { alert("pr
javascript Code - JSP-Servlet
javascript Code  how to count controls in form and find no of contriols in html or jsp page.for example one table is there with 10 rows,each row consists of 3 fields as 2 text box and one drop down box
rtf_jsp_javascript
rtf_jsp_javascript  Hi every one plz give me answer for below question ASAP I created one JSP(used pre defined javascript in jsp to get rtf format in browser) which creats RTF Format in browser to enter data. MY question
javascript for textbox - JSP-Servlet
javascript for textbox  Dear sir , How to write a javascript... a javascript to do so ..Please help me sir... Thanks...  Hi Friend, Try...:8080/examples/jsp/deleteuser.jsp?id='+id,'mywindow','width=500, height=350,toolbar
Servlets,Jsp,Javascript - JSP-Servlet
Servlets,Jsp,Javascript  Hi in my application i am creating a file... ExportToExcel button, jsp Upload plot nos (.xls format). GO Reset ExportToExcel javascript function excelExport() { document.body.style.cursor="wait
JSP Variable in Javascript
JSP Variable in Javascript          JSP Variable in Javascript helps you to pass jsp variable to javascript. The JavaScript include a function
javascript - JSP-Interview Questions
Javascript string functions contains  What is the Javascript string functions contains
javascript-html - JSP-Servlet
javascript-html  i want to dynamically create textfield with option button as another/remove when user presses in jsp page which will be in table.for example table contains one row with 2 columns,one textfield,second dropdown
jsp netbeans javascript
jsp netbeans javascript  hi to all; I'm debutante in JSP netbeans... nothing is changed.) 2-how iserer date in oracle 10g database via JSP netbeans... to connect) 4-field test in javascript: how to check that the field in a number
javascript - JSP-Servlet
javascript  how to convert a string to long in javascript
javascript - JSP-Servlet
Disabled JavaScript on Browser  How can i disabled JavaScript for a particular browser
javascript-html - JSP-Servlet
javascript-html  i want to dynamically create textfield with option button as another/remove when user presses in jsp page which will be in table.for example table contains one row with 2 columns,one textfield,second dropdown
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...('http://localhost:8080/examples/jsp/deleteuser.jsp?id='+id+'&&reas='+reason
javascript - JSP-Servlet
javascript  i dont have the jsp code . using simple jsp file and without using alert message box.i need using of getElementByID
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 prompt - JSP-Servlet
javascript for prompt  Dear Sir, I am using a prompt() for taking a reason for delete.I used your code,its working fine .but i am validating...() in javascript. Thanks
javascript - JSP-Interview Questions
javascript open new window popup  How to open new window in popup view using JavaScript?  hi friend,<html><title>new window page</title><head></head><body><FORM><INPUT type
JSP Value to JavaScript
JSP Value to JavaScript          JSP Value to JavaScript tells you to pass the value from JSP to JavaScript. The JavaScript create a function
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 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
how to assign javascript variable value to a jsp variable
how to assign javascript variable value to a jsp variable  how to assign javascript variable value to a jsp variable
javascript - JSP-Servlet
;i dont have the jsp code . using simple jsp file and without using alert
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 am checking a that reason cannt exceed 256 length,if it exceed i have to give
javascript - JSP-Servlet
javascript  how to generate html table in current jsp page with other form fields with given value in text field.i want to generate subject course table in existing form (which already contains some textfield) each row contains
javascript - JSP-Servlet
javascript  hi sir.i am preparing one application in jsp which contains 10 rows,each row contains 2 fields,2 fields are droop down list box,in these controls am getting values from database when form is requested.i.eretrieving 3
passing value from javascript to jsp - JSP-Servlet
passing value from javascript to jsp  Hi... Is there any way to get the value from the javascript and print it on the current jsp page or print an array onto the current jsp page using javascript  Hi Friend, We
how to get javascript variables into jsp - JSP-Servlet
how to get javascript variables into jsp  How to pass variables from java script into jsp page  Hi Friend, Try it: 1)pass.jsp: var msg="Hello World" window.location.href="show.jsp?value=" + msg
How to pass javascript variable in Scriplet of JSP?
How to pass javascript variable in Scriplet of JSP?  How can I assign the value of a javascript variable to a variable declared in jsp scriplet? Is it possible
Help with javascript function - JSP-Servlet
Help with javascript function  I've got a button in a for loop.Each button gets its name property dynamically: The Code is as follows... properties of those clicked buttons to be transferred to the next jsp page
javascript code problem - JSP-Servlet
javascript code problem  Thanks for sending answer.but actually what...; "> in above code which is jsp and struts form bean... hidden variable and write javascript code so that all tables values are added
how to invoket javascript function in JSP - JSP-Interview Questions
how to invoket javascript function in JSP  Dear Sir, my question is how to invoke javascript function written in .js file into our JSP. using which tag in JSP this is possible
javascript programing error - JSP-Servlet
javascript programing error  hi deepak i m using explorer to run javascript program in this there is no option to check error will u plz tell me the way to check error in explorer as we can check with mozila
passing values form javascript - JSP-Interview Questions
passing values form javascript  please i want to pass values from javascript function to jsp code how can i do
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... javascript. It can be working in localsystem. once uploaded into the server
i want to pass Javascript value to JSP scriptlet..
i want to pass Javascript value to JSP scriptlet..  i am having a problem that, i am having a combo box in the JSP page when i select an item from that i am calling the onchange function. In javascript i am getting the value
Javascript List Box - JSP-Servlet
Javascript List Box  Thanks vdeepak for sending answer.But i tried ur example but i failed.actuall am doing in struts 1.1. this is my code Select Semester: Select One Subject Code Subject
Html/JavaScript code - JSP-Servlet
Html/JavaScript code  I have 2 JSPs JSP1 and JSP2. 1.in JSP1 i have a table being displayed using the tag and cells in it contain links(huge amount of data is displayed in paged manner). 2.When click on a link, it leads
Transferring values between javascript and java code in jsp - JSP-Servlet
(s); } 2)Pass value from javascript to Jsp scriplet...Transferring values between javascript and java code in jsp  ..., expressions etc) in a jsp page?   Hi Friend, 1)Pass value from jsp
unicode support in javascript - JSP-Servlet
the tha text in a text box and sending it to next jsp. we are using UTF-8 encoding for jsp and charset as windows-874 for html meta charset. Can anybody help me... to server functionality We are already using encodingfor jsp 1)and client
callig jsp file from javascript function - JSP-Servlet
callig jsp file from javascript function  I want to call a jsp file from javascript function. What I want to do is Whenever a user clicks on a form in html, the function should call specified jsp file.The form has no dynamic
Dynamic row genertion in javascript? - JSP-Servlet
Dynamic row genertion in javascript?  Hi roseindia, I want coding in javascript to add a dynamic row in jsp..This row contain 3 fields(2 textfields,1 textarea).Every time if i click add button have to add dynamically
Calendar In JSP Using JavaScript
Calendar In JSP Using JavaScript   ... in JSP using JavaScript. We created the following files for the application...:150px;'><a href="javascript:window.close()">Window Close<
how to generate automatic bill based on selected values using jsp/javascript?
how to generate automatic bill based on selected values using jsp/javascript?  how to generate automatic bill based on selected values using jsp/javascript

Ads