Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP/Javascript DropDown List problem  RSS feed

 
Clarence Dyho
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

I have a JSP with a drop down list of country codes. Since the list of contries does not come from a database, I used a javascript function to populate the drop down list with values. When I retrieve a record from the database and pass it to the form, I need to set the drop down list to show the country code for that record. I can't seem to make this work since the JSP is compiled and built before the javascript function runs so the drop down list always defaults to the first entry. Any way to make this work? Thank you.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65832
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"clarence_dyho",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65832
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why on earth are you populating the dropdown in Javascript? Why not just create it on the JSP end -- so much easier and straight-forward.
 
Kalai Selvan
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
It will be good if you post your code fragment along with such question. Anywayz, you can set the value of a combo box after loading the combo box by using the javascript...



Kalai Selvan T.
 
Clarence Dyho
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear:
Thank you for reminding me. I have updated my profile. =)
The countries are not maintained in a database and I was looking for a way where I can get the list and that list should easily be updated, hence, I was thinking of creating a tag-lib for this or just a javascript using:

document.write("<option value=\"USA\">United States</option>");

This works well except that when records are pulled from the database and into the form, the country displayed in the drop down list is the first one instead of the correct one. You are right, however, that is it easier to create it in the jsp.


Kalai: It worked! Thank you very much for your help. =)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!