need help...................please

need help...................please

I have a problem in my JSP Coding. How to retrive value from database in to text field when user select one value from dropdown list. For example, if user select on of name in dropdown list (the name list is also coming from database)every information about the person should show in texfield that already create in the web page. I'm really stuck on this area. Please help me.

By the way, I'm using access Database and JSP coding.

Thank You.

View Answers

July 9, 2012 at 12:57 PM

Here is an application that retrieves table name from database and display in dropdown box. When the user select particular name from dropdown corresponding values will get displayed into textboxes.

1)selectname.jsp:

<%@page import="java.sql.*"%>
<html>
<head>
<script type="text/javascript">
function showEmp(emp_value){ 
 if(document.getElementById("address").value!="-1"){
 xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
 alert ("Browser does not support HTTP Request")
 return
 }
var url="getvalue.jsp"
url=url+"?name="+emp_value
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
else{
 alert("Please Select Employee Id");
}
}
function stateChanged(){ 
document.getElementById("email").value ="";
document.getElementById("address").value ="";
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
var showdata = xmlHttp.responseText; 
    var strar = showdata.split(":");
if(strar.length==1){
  document.getElementById("address").focus();
  alert("Please Select Employee Id");
  document.getElementById("email").value =" ";
document.getElementById("address").value =" ";
 }
 else if(strar.length>1) {
var strname = strar[1];
document.getElementById("address").value= strar[1];
document.getElementById("email").value= strar[2];
 }
 } 
}

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 border="0" width="400px" align="center" bgcolor="#CDFFFF">
<div id="mydiv"></div>
   <tr><td><b>Select Employee Name</b></td><td> 
   <select name="name" onchange="showEmp(this.value);">
   <option value="-1">Select</option> 
   <%
   Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/test","root","root");
String query = "select * from employee";

Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next())
{
%>
<option value="<%=rs.getString("name")%>"><%=rs.getString("name")%></option>
<%
}
%>
 </select>
</td></tr>
<tr><td ><b>Employee Address:</b></td><td>
<input  type="text" name="address" id="address" value=""></td></tr>
<tr><td><b>Employee Email:</b></td><td>
<input  type="text" name="email" id="email" value=""></td></tr>

</table>
</form>    
<table border="0" width="100%" align="center">
<br>
<br>
</table>
</body>
</html>

2)getvalue.jsp:

<%@page import="java.sql.*"%>
<%
String emp_id = request.getParameter("name").toString();
String data="";

int sumcount=0; 
Statement st;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/test","root","root");
String query = "select * from employee where name='"+emp_id+"'";

st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next())
{
data = ":" + rs.getString("address") +":"+  rs.getString("email");
}
out.println(data);
}
catch (Exception e) {
e.printStackTrace();
}
%>

July 9, 2012 at 12:58 PM

3)For the above code, we have created following table:

CREATE TABLE employee (
id bigint(255) default NULL,
name varchar(255) default NULL,
address varchar(255) default NULL,
contactNo int(255) default NULL,
email varchar(255) default NULL
)


July 9, 2012 at 12:59 PM

Please visit the following link:

http://www.roseindia.net/jsp/comboSelect.shtml


July 9, 2012 at 5:31 PM

thank you very much









Related Tutorials/Questions & Answers:
need help please
need help please  Dear sir, my name is logeswaran. I have a big problem that I can't find the solution for a program. How can I block a user from enter a page second time. Please help me. By the way I'm using Access database
i need a help in this please
i need a help in this please  The factorial of a nonnegative integer n is written n! (pronounced â?? n factorialâ??) and is defined as follows: n!=n . (n-1) . (n-2) . .... . 1 (for values of n greater than or equal to 1) and n!=1
Advertisements
need help...................please
need help...................please  I have a problem in my JSP Coding... on this area. Please help me. By the way, I'm using access Database and JSP coding...("GET",url,true) xmlHttp.send(null) } else{ alert("Please Select Employee Id
help please?
help please?  Define a class named Circle with the following properties: â?¢ An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both data fields
help please?
help please?  Define a class named Circle with the following properties: List item â?¢ An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
help please?
help please?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
help please?
help please?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
help please?
help please?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
help please?
help please?  Define a class named Circle with the following properties: ? An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both data fields
Confusion on Functions. Help Please?!
Confusion on Functions. Help Please?!  Write a program which has a number of functions for getting the area i.e. area of circle, area of square, area... not getting anywhere with it really :( Some help please
Java Variables Help Please!
Java Variables Help Please!  Hi, I just started with java and i need help with my school project, this is it so far: import java.util.*; public class ProjectCS { public static void main(String[] args) { welcome
help please!!! T_T
help please!!! T_T  what is wrong in this?: import java.io.*; class...("please enter your name:"); name1= input.readline(); System.out.println("please... { String name1; String name2; System.out.println("please enter
Logic error? HELP PLEASE! :(
Logic error? HELP PLEASE! :(  Hello Guys! i have a huge problem. What... your saved Quick Quotes, please enter your Email Address...("emailAddress")) + " Please input a valid email address
Help please, some strange errors
Help please, some strange errors  Sorry about this messy formatting. As a beginner in java i got no idea which part of the code is creating... is causing that run-time errors? Any kind of help will be helpful to me. and let
help please
help please  hi i am done with register application using jsps servlets htmls. But i couldnt imp one thing that.. Wen u login to ur account browser... file.. Or atleast help me with code here.. I tried checking session alive
Not sure whats wrong with my code HELP PLEASE?!?!
Not sure whats wrong with my code HELP PLEASE?!?!  I cant figure out what I am doing wrong in my code can anyone help me out??? Grades ADS_TO_REPLACE_1 function computeGrade( ) { var hw, lab, midt, fin, avg; hw
Grid World project Run Error !! help please!!
Grid World project Run Error !! help please!!  i'm trying to make a bug multiply when it hits a rock or another bug or a side the bug will remove...(EventDispatchThread.java:122) thank you...PLEASE HELP ME!!   ignore
help please - Java Beginners
help please  i wrote this program but the function newLine dosnt work with me and i dont know where is exactly the error this is the code i wrote import java.io.*; import java.util.*; import java.lang.Integer
Java Help Please
Java Help Please  I can't seem to figure out how to make this program, can some one help me please? It is due soon!! 4) Write a program that will take an input (Date object will contain fields for the month, day, and year - all
Begineer Help Help Please Thanks A million ) I am using Jcreator
Begineer Help Help Please Thanks A million ) I am using Jcreator  System.out.println(" Income Statement"); System.out.print("Year
need
need  i need a jsp coding based project plz help me
Need of ORM
Need of ORM  Why do you need ORM tools like hibernate
need of code
need of code  howto convert greyscale image to binary image in java
need coding
need coding  sir i need code for simple bank application in jsp please send it   sir i need the coding for simple bank application in jsp.   Please visit the following link: Jsp Bank Application
Need Suggistion
Need Suggistion  how to call a callable statement in our jSp page using Struts environment
urgent need
urgent need   Input a line. Count the number of words that start with a capital letter
Need Project
Need Project  How to develop School management project by using Struts Framework? Please give me suggestion and sample examples for my project
need to Program
need to Program   Can any one help me on below How to insert more then one records in EXCEL Sheet using JSP
need query
need query  hi sir , i am beginner to sql.i need a query so that it can be helpful to my project. i have four tables each containing different fruits with different amounts. i need a query in such a way that when i say some
need
need
need project
need project  hi im new on this site so dnt knw actual procedure . but i need a project on banking system in java with sql database. which should... is good plz add it i need project till Saturday i.e 10th march 2012 plzzzz
need answer
need answer  Given a phone number, as a string, generate the lettercombinations that are possible based on the telephone keypad's number/letter relationship (ie, 1 is related to no letters, 2 is related to 'a' 'b' 'c', 3
Need help
Need help  Hello... I need some help I have a method which contains 1 string value and i wnat when this method get called den that string value should b assigned as array name.. for example.. i have a method name() which
Need help
Need help  Hello... I need some help I have a method which contains 1 string value and i wnat when this method get called den that string value should b assigned as array name.. for example.. i have a method name() which
Need of JUnit
Need of JUnit  Hi sir, What makes JUnit better than other testing tools for Java Unit testing?   Hi friend.. It is better to know.... There's no need to manually comb through a report of test results.ADS_TO_REPLACE_2 4
Need help
. This name list should get from the database. Please help me. By the way, I'm...Need help  Dear sir, I have a problem. How to write JSP coding, if a user select a value from drop down list for example department, the another drop
NEED A PROG
NEED A PROG   whats the program to add,delete, display elements of an object using collecions. without using linked list   Hi Friend, Try the following code: import java.util.*; class CollectionExample { public
need code
need code  Create Vehicle having following attributes: Vehicle No., Model, Manufacturer and Color. Create truck which has the following additional attributes:loading capacity( 100 tons?).Add a behavior to change the color
need code
need code  Create Vehicle having following attributes: Vehicle No., Model, Manufacturer and Color. Create truck which has the following additional attributes:loading capacity( 100 tons?).Add a behavior to change the color
need code
need code  Create Vehicle having following attributes: Vehicle No., Model, Manufacturer and Color. Create truck which has the following additional attributes:loading capacity( 100 tons?).Add a behavior to change the color
Need help with this!
Need help with this!  Can anyone please help me... to a file at all at this time. Any help would be greatly appreciated, thank you... //Menu Option 1 if(entry == 1) { System.out.println("Please enter the amount
need sourcecode - Java Beginners
need sourcecode  Hai, I need program for packetization for videos
need ENUM examples
need ENUM examples  i need enum sample examples
need of frameworks in java?
need of frameworks in java?  What is need of frameworks in java
need of frameworks in java?
need of frameworks in java?  What is need of frameworks in java
need of frameworks in java?
need of frameworks in java?  What is need of frameworks in java
need of frameworks in java?
need of frameworks in java?  What is need of frameworks in java
ModuleNotFoundError: No module named 'need'
ModuleNotFoundError: No module named 'need'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'need' How to remove the ModuleNotFoundError: No module named 'need' error
Need sample code
Need sample code  Need code for graph which shows the performance comparission of aprior algorithm and coherent rule algorithm.plz can any one help me i need in a week

Ads