This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes Populating a value based on the option selected in the dropdown Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Populating a value based on the option selected in the dropdown" Watch "Populating a value based on the option selected in the dropdown" New topic
Author

Populating a value based on the option selected in the dropdown

anita prat
Greenhorn

Joined: Aug 11, 2011
Posts: 8
Hi,
I have a jsp here I have a drop down list that contains the list of franchises. There is nother field franchise code on the jsp which will have the value populated based on the valkue in the drop down. These two are properties of a form bean Franchise which is available in the form bean associated with the jsp.
FranchiseVO bean has properties franchisename and franchisecode. THe names appear in the dropdown. Based on the franchisename selected , the value of the franchise code should get populated. How do I acheive this? Do I need to use a hidden parameter to pass to the javascript?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

That depends what you mean by "selected". Do you mean:

  • The value that will be set as selected by the JSP -- and therefore known at page-generation time.
  • The value that will be chosen by the end user after the page has been displayed in the browser.


  • [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    anita prat
    Greenhorn

    Joined: Aug 11, 2011
    Posts: 8
    The value that will be chosen by the end user after the page has been displayed in the browser.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60810
        
      65

    Well, by that time the JSP has been evaluated on the server and is long gone. So you'll need to handle the change event for the dropdown on the client using JavaScript.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Populating a value based on the option selected in the dropdown
     
    Similar Threads
    Comparing values using JSTL
    JSTL eq condition
    Retain option selected value on submit
    Populating one drop down based on the other
    Page submission on change of drop down value not working