• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

populating drop-down boxes

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this client-side or server-side JavaScript?
bear
 
jen franzke
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
client-side (?). It is in the head of a .jsp file.
 
Ranch Hand
Posts: 937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help!
reply
    Bookmark Topic Watch Topic
  • New Topic