473,434 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

How to create a select list based on options from another select list

<form name='aForm'>
Category:

<select name='category'onchange="additems()">
<option value='None'>None selected yet
<option value='Toy'>Toy
<option value='City'>City
<option value='Major'>Major
</select>


Your Selection:

<select name='myChoice'>

</select>
</form>

<input type='button' value='Submit' onclick='send()'>

<script>
function additems(){
var=document.aForm.category.selectedIndex;
if(var=='None'){
document.aForm.mychocie.options[0]=new option("None selected yet","None selected yet")
};
if(var=='Toy'){
document.aForm.myChoice.options[0]=new option("Bicycle","Bicycle")
document.aForm.myChoice.options[1]=new option("Jump Rope","Jump Rope")
document.aForm.myChoice.options[2]=new option("Frisbee","Frisbee")
doucment.aForm.myChoice.options[3]=new option("Doll","Doll")
};
if(var=='City'){
document.aForm.myChoice.options[0]=new option("Akron","Akron")
document.aForm.myChoice.options[1]=new option("Santa Fe","Santa Fe")
document.aForm.myChoice.options[2]=new option("Portland","Portland")
document.aForm.myChoice.options[3]=new option("Atlantic City","Atlantic City")
};
if(var=='Major'){
document.aForm.myChoice.options[0]=new option("Art","Art")
document.aForm.myChoice.options[1]=new option("Physics","Physics")
document.aForm.myChoice.options[2]=new option("Public Relations",Public Relations")
};




};
function send(){

};
</script>
Sep 29 '10 #1
1 1715
First and foremost, this belongs in the Javascript/Ajax/DHTML section.
There are several things you may want to try:
First of all, the options in a select DOM aren't an array - if you want to change them, you'll have to remove them, then add the new ones.
You're missing some semicolons, and have some spelling errors (doucment, mychocie instead of myChoice).
Try reading up on the add() and remove() methods of the select DOM, and the examples:
http://www.w3schools.com/jsref/met_select_add.asp
http://www.w3schools.com/jsref/met_select_remove.asp
Sep 30 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: GiSmo | last post by:
hello I'm french so I hope I hunderstand your answers ! I'm begginer in javascript and I would like to do this : select all elements of one selection list (html) with a javascript fonction ...
6
by: passion_to_be_free | last post by:
This is probably simple, but I can't seem to find it anywhere. I have have some values stored in javascript variables. I have a <select> dropdown list whose options correspond to these values. I...
3
by: Brian Henry | last post by:
So what is the easiest way to do this? I have one list view with a list of items (in detail view and with about 20 sub items) and a second list view that will take the items they drag from the...
5
by: Muskito | last post by:
Hi, Is it possible to copy the entire List(Of type) object to another List(Of type) object (they are both of the same type ofcourse) - without keeping the reference? There's the CopyTo...
4
by: bob_jeffcoat | last post by:
Hi, Have class B which subclasses from class A. I have a List<B> and I'm trying to get a List<A> without writing a stupid loop everytime I want to do it. So I tried this method: public...
14
by: fool | last post by:
Dear group, Thanks for all those who helped previously. Now I get some value printed. Is that the value of the list getting printed? Am I really polluted the list? Previous thread link...
6
by: psbasha | last post by:
Hi, I am assigning the list/dict values to another list/dict variable as shown below. List : List1 = List2 = List1
9
by: Stephan Steiner | last post by:
Hi I seem to have a bit of trouble understanding one bit of how generics work: In C#, every class automatically derives from object, and inherits a bunch of properties (i.e. ToString()). Thus,...
1
by: MasterStarr | last post by:
I Have A Music Player I Made Using A Tutorial In Visual basic 2008 And The Play Button For This Player Plays The Songs Fine, But The Problem Is The Code: AxWindowsMediaPlayer1.Ctlcontrols.next() ...
5
maxamis4
by: maxamis4 | last post by:
Hello, I am currently building a php website. My input form has a list box which I have populated using mysql. What i want to do is populate another list box using the first list box. ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.