0

hi all,

I am having 1 combo box and 3 text boxes in my jsp page.

combo box is empid and and the other are name,desig and dept.

when i select the empid, need to come all other values into text box fields from database.

any ideas please share with me.

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by javaAddict
0

Simple way:
When you change the select box use javascript to submit the form to the same page. When you do that take from the request the value of the select box.
Remember the first time you load the page, there is nothing in the request, so if you try to get the value from the select box it would be null.
When you submit to the same it will not be null.
When it is not null call a method and get the data:

yourPage.jsp

<%
String name = "";
...

String empId = request.getParameter("empId");
if (empId!=null) { // it means you submitted to the page
  // call the method to get the data from the database
  name = "data from database";
}
// if empId is null do nothing since you went to page without submitting
%>

...

<form action="yourPage.jsp" id="yourPageForm" name="yourPageForm" >
  Name: <%= name%>
  ...
</form>

Add an onchange event at the select box and submit the form. The form will submit to the same page:

<%
String name = "";
...

String empId = request.getParameter("empId");
if (empId!=null) { // it means you submitted to the page
  // call the method to get the data from the jsp
  name = "data from database";
}
// if empId is null do nothing since you went to page without submitting
%>

...

<form action="yourPage.jsp" id="yourPageForm" name="yourPageForm" >
  Name: <%= name%>
  ...

  <select id="empId" name="empId" onchange="document.getElementById('yourPageForm').submit();">
    ....
  </select>

</form>

I would advice you to study javascript:
http://w3schools.com/
Also when you get the empId you might want to check if it is empty or not

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.