Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need to choose a value from list item in jsp  RSS feed

 
Britto Moris
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
I need to choose the value of a list item in jsp. There are many employees in various departments and i need to choose that employees in department wise.


Example. I have two list items in jsp
1. Select dept_no,dept_name from departments
2. SElect emp_name from employees, departments where emp_dept_no=curr_dept_no and curr_dept_no = dept_no

These two are the list items. When i choose the department from the first list item i need to display the employees in that particular department in the second list.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to assume that by "list item" you mean a select/option control. So if I understand correctly, the contents of the second select control are dependent on the choice made in the first select control.

So, populate the first select control on page load (the $(document).ready(function())). For the second one, use jQuery to bind the "onChange" event to an Ajax call that returns the list of employees.

This probably needs to be moved to our JavaScript forum, but before I do that, let me make sure I understand your requirements and that you intend to use JavaScript to accomplish this.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch!
 
Britto Moris
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Mr. Kevin Robbins. And what you understand is exactly correct. Both list item values are obtained using SQL queries.
Will you please help me to solve this issue.
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's your turn.
What have you tried?
What have you researched? There were several keywords that Kevin mentioned.

First steps:
Populate a select element with the list of departments.
Write a service/servlet that takes a department id, and returns a list of employees in that department - in a format that Javascript can understand.
Wire up the onclick event to on the element in the first step to make an ajax call to the service in the second step, and populate the second select box with the results.

If you get stuck, we can probably provide some pointers and help, but you have to do this yourself.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Stefan has indicated, we are a learning site, not a code mill. We expect you to ShowSomeEffort. One of the basic skills needed for programming is the ability to take a large problem and break it down into smaller, manageable problems. Stefan has done that for you with three good starting points. Take the first one and give it a shot. Post your results here and tell us where you are having trouble and we'll help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!