aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes dependent select list options 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 "dependent select list options" Watch "dependent select list options" New topic
Author

dependent select list options

m brymer
Ranch Hand

Joined: Jan 04, 2005
Posts: 64
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!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

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.


[Jess in Action][AskingGoodQuestions]
m brymer
Ranch Hand

Joined: Jan 04, 2005
Posts: 64
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!
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
How about you show me the code after your server side code has run.

Eric
m brymer
Ranch Hand

Joined: Jan 04, 2005
Posts: 64
Hi Eric,
Below is the entire code for this jsp page, nothing to fancy...

m brymer
Ranch Hand

Joined: Jan 04, 2005
Posts: 64
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

Joined: Jan 04, 2005
Posts: 64
Can anyone help me?
m brymer
Ranch Hand

Joined: Jan 04, 2005
Posts: 64
okay, I have tried something new but am still not getting the right output can someone take a look? Thanks!
m brymer
Ranch Hand

Joined: Jan 04, 2005
Posts: 64
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

Joined: Jan 04, 2005
Posts: 64
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>
Padmanaban Jayabalan
Greenhorn

Joined: May 08, 2002
Posts: 14
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: dependent select list options