wood burning stoves
The moose likes HTML, CSS and JavaScript and the fly likes populating drop-down boxes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "populating drop-down boxes" Watch "populating drop-down boxes" New topic

populating drop-down boxes

jen franzke

Joined: Mar 13, 2003
Posts: 6
I need to populate a drop-down list in a form with a list of Country Codes that can be obtained by calling CountryCode.getCountryCodes(), which returns a List. I am trying to use a JavaScript function to do this, but it doesn't seem to be working. I have included the code below. I am still new to JS, so please be kind.

<script language="JavaScript1.2">
import jblocks.data.CountryCode;
function loadCountryCodes() {
countryCodes = new Array(CountryCode.getCountryCodes().size());

for (i = 0; i < countryCodes.length; i++) {
countryCodes[i] = CountryCode.getCountryCodes().get(i);

document.Table2FORM.nationality.options = countryCodes;
...and right before the <form> tag...
<script language="JavaScript1.2">loadCountryCodes();</script>

Any help that can be offered would be much appreciated!
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
look at this and see if it helps you out any
It shows you how to add the information to the select element.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63343

Is this client-side or server-side JavaScript?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
jen franzke

Joined: Mar 13, 2003
Posts: 6
client-side (?). It is in the head of a .jsp file.
sunitha reghu
Ranch Hand

Joined: Dec 12, 2002
Posts: 937
Then can u pls explain this
import jblocks.data.CountryCode;
r u populating the second drop down box frm a query frm db or u have the data upfront?
jen franzke

Joined: Mar 13, 2003
Posts: 6
jblocks.data.CountryCode is the class where the data resides. CountryCode.getCountryCodes returns a List of CountryCodes. So the data is in a class, not in a database.
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
<select name=nationality>
<%for (int i = 0; i < countryCodes.length; i++) {%>
<option value="<%=CountryCode.getCountryCodes().get(i)%>"><%=CountryCode.getCountryCodes().get(i)%></option>
[ April 01, 2003: Message edited by: Yuriy Fuksenko ]
[ April 01, 2003: Message edited by: Yuriy Fuksenko ]
jen franzke

Joined: Mar 13, 2003
Posts: 6
Thanks for the help!
I agree. Here's the link: http://aspose.com/file-tools
subject: populating drop-down boxes
It's not a secret anymore!