• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Populate Text Fields based on dropdown

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have list of employees in my database and their associated information like employeeId,supervisor and process. I have class named EmployeeDetails having same properties. I am fetching details of all users using below code:



In employeeList, we have list of objects having data of employees. I donot know how to get which object is selected in dropdown and based on that rest of the text fields are populated. Example:
Name ID Supervisor
-------------------------------------------------------
Pawan Kumar 3033045 Vimal Kumar
Vimal Kumar 3040901 Dinesh Hemrajani

If Pawan Kumar is selected from dropdown then '3033045' and 'Vimal Kumar' should get populated.

Please help!!!
 
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two things:
  • You should not be using Java scriptlets in your JSP. That is an obsolete and discredited practice from over 12 years ago. (12 years! ) You should be using the JSTL and EL.
  • In order to handle changes made to the selected value, you will use JavaScript.
  •  
    Viky Kizz
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks.....i will remove JSTL or EL.

    What i am not getting is how would i pass EmployeeDetails object to javascript and then use it assign value to my textfields. As, i selected one of the EmployeeName from dropdown the object from which employeename is fetched need to be passed to javascript and the use that object to use rest of the getters method. But, we cannot use java objects in javascript.

    So, is there a way i can refer the object of which name is selected in dropdown from javascript .
     
    Bear Bibeault
    Sheriff
    Posts: 67682
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Viky Kizz wrote:Thanks.....i will remove JSTL or EL.


    Remove? You should be using JSTL/EL in place of Java scriptlets.

    What i am not getting is how would i pass EmployeeDetails object to javascript and then use it assign value to my textfields. As, i selected one of the EmployeeName from dropdown the object from which employeename is fetched need to be passed to javascript and the use that object to use rest of the getters method. But, we cannot use java objects in javascript.


    That's correct -- you cannot mix the Java and the JavaScript. Once the page is sent to the browser, all Java is done. See this article if you want an explanation of that.

    What you'd need to do is to handle changes to the select element with a change handler, that goes back to the server via an Ajax request. The Ajax request can either return a pre-formated HTML fragment to replace the form (you can use a JSP fragment for this), or it can return JSON data for the field values, and JavaScript would be used to update the fields values. For this usage, where only the field values need to be replaced, I'd probably go with the JSON route.

    For all of this, I'd use jQuery's help with the JavaScript. Life is too short to deal with cross-browser issue in event handling and Ajax.

    So, is there a way i can refer the object of which name is selected in dropdown from javascript .


    The value of the options should be the id of the represented items so that you know which item was selected.
     
    Straws are for suckers. Now suck on this tiny ad!
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic