• 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

dependent select list options

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I have created a jsp page with box1 and box2 with box2 dependent on what is selected in box1. If US is chosen from box1 I want box2 to display a list of all states. i have stored all of the states in a vector but I can't seem to get them to read into box2. Can anyone take a look and see what I am doing wrong? I think it is syntax but not sure. Thanks!
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Although this is a JSP, it seems to actually be a JavaScript question, so I'm going to move your question to our HTML and JavaScript forum.
 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone help me with this? I have tried everything I could think of but still can't seem to read the vector into the select options. Thanks!
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about you show me the code after your server side code has run.

Eric
 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric,
Below is the entire code for this jsp page, nothing to fancy...

 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I got it to show the options on the screen but not in the right format, is there anyway to format these options in javascript? Here is the new piece of code



the output looks like <option value="AL">Alberta<option value="BC">British Columbia...
 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone help me?
 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay, I have tried something new but am still not getting the right output can someone take a look? Thanks!
 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone help me with this? I have been trying everything for the last few days and can't seem to get this to work. I get close but not the right format...Please
 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the source code I get, you see that everything is there just not the right format.

<script language="javascript">
function setOptions(o)
{

var select2 = document.geo.select2;
select2.options.length = 0;

if (o == "United States")
{
select2.options[select2.options.length] = new Option(' <option value="AL">Alabama<option value="AK">Alaska<option value="AZ">Arizona<option value="AR">Arkansas<option value="CA">California<option value="CO">Colorado<option value="CT">Connecticut<option value="DE">Delaware<option value="FL">Florida<option value="GA">Georgia<option value="HI">Hawaii<option value="ID">Idaho<option value="IL">Illinois<option value="IN">Indiana<option value="IA">Iowa<option value="KS">Kansas<option value="KY">Kentucky<option value="LA">Louisiana<option value="ME">Maine<option value="MD">Maryland<option value="MA">Massachusetts<option value="MI">Michigan<option value="MN">Minnesota<option value="MS">Mississippi<option value="MO">Missouri<option value="MT">Montana<option value="NA">National<option value="NE">Nebraska<option value="NV">Nevada<option value="NH">New Hampshire<option value="NJ">New Jersey<option value="NM">New Mexico<option value="NY">New York<option value="NC">North Carolina<option value="ND">North Dakota<option value="OH">Ohio<option value="OK">Oklahoma<option value="OR">Oregon<option value="PA">Pennsylvania<option value="RI">Rhode Island<option value="SC">South Carolina<option value="SD">South Dakota<option value="TN">Tennessee<option value="TX">Texas<option value="UT">Utah<option value="VT">Vermont<option value="VA">Virginia<option value="WA">Washington<option value="WV">West Virginia<option value="WI">Wisconsin<option value="WY">Wyoming');
}
if (o == "Canada")
{
select2.options[select2.options.length] = new Option(' <option value="AL">Alberta<option value="BC">British Columbia<option value="MN">Manitoba<option value="NW">NW Territory<option value="NA">National<option value="NB">New Brunswick<option value="NF">Newfoundland<option value="NS">Nova Scotia<option value="NU">Nunavut<option value="ON">Ontario<option value="PE">Prince Edward Island<option value="QE">Quebec<option value="SP">Saint Pierre & Miquelon<option value="SA">Saskatchewan<option value="YU">Yukon');
}
if (o == "3")
{
select2.options[select2.options.length] = new Option('Chicken');
select2.options[select2.options.length] = new Option('Fish');
}
}
</script>
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Brymer,

You may try this doing with the help of a Javascript rather than using vectors. Please follow the link for reference.
http://javascript.internet.com/forms/country.html

You may keep the values in another JS file from where you can retriev instead of taking it from the same page. This will be helpful if this is to be used in more than one place of your application.

Hope this will solve your problem
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic