Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

populating drop-down boxes

 
jen franzke
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
client-side (?). It is in the head of a .jsp file.
 
sunitha reghu
Ranch Hand
Posts: 937
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Yuriy Fuksenko
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for the help!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic