aspose file tools*
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


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "populating drop-down boxes" Watch "populating drop-down boxes" New topic
Author

populating drop-down boxes

jen franzke
Greenhorn

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;
}
</script>
...and right before the <form> tag...
<script language="JavaScript1.2">loadCountryCodes();</script>

Any help that can be offered would be much appreciated!
-Jen
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
look at this and see if it helps you out any
http://www.javascriptkit.com/script/cut183.shtml
It shows you how to add the information to the select element.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61594
    
  67

Is this client-side or server-side JavaScript?
bear


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

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
Greenhorn

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
<form>
<select name=nationality>
<%for (int i = 0; i < countryCodes.length; i++) {%>
<option value="<%=CountryCode.getCountryCodes().get(i)%>"><%=CountryCode.getCountryCodes().get(i)%></option>
<%}%>
</select>
</form>
[ April 01, 2003: Message edited by: Yuriy Fuksenko ]
[ April 01, 2003: Message edited by: Yuriy Fuksenko ]
jen franzke
Greenhorn

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