Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp combo box  RSS feed

 
satheesh subramani
Greenhorn
Posts: 29
Fedora Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i have two combo boxes one for country and another for state
both populated from data base dynamically.




the variable city in scriptlet is always pointing to the last value of the first combo box
how it make dynamically
help me please
 
Allen Bandela
Ranch Hand
Posts: 128
Eclipse IDE MS IE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sateesh,

It appears that you want to display the states in the second combo box based on country selected in the first combo box. If that is correct, then the following is one way to accomplish that.

Firstly, it appears that you are storing the country in a variable called 'city'. That's OK. Now, the reason 'city' contains the last value in the first combo box is because it is a server-side variable in the Servlet's service() (or doGet or doPost) method that your server translates to. In your scriptlet, it was last assigned to the last value retrieved from the database, which is the last value in the first combo box.

If you want it to be the value chosen by the user, you have to send the selected value to the server in a new request as follows:

Then use the "ctry" input parameter value to retrieve the state from the database and display in a new page.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some tips:
  • Use correct terminology. It's not a "combo box". See HtmlHasNoComboBox.
  • Java code in a JSP is poor practice that has been discredited for 9 years now. Time to update your knowledge.
  • Database access should not be performed in the user interface layer.
  • Modern web apps will use Ajax to fetch the entries for the second dropdown when the value of the first is chosen. See the HTML form for dozens of previous discussions of this.
  •  
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!