javascript thread: Javascript to add items to listbox based on selection in another listbox
this.FORM1 isn't going to work because "this" = the element that triggered
the event = the other select control, which does not have FORM1 as a
property.
You want to say "document.FORM1".
-Roy
-----Original Message-----
From: Femy Praseeth [mailto:fpraseet@s...]
Sent: Friday, October 25, 2002 7:24 PM
To: javascript
Subject: [javascript] Javascript to add items to listbox based on
selection in another listbox
Hi all
I am new to this list and new to Javascript. I would appreciate any help
from the experts on this proble I have. have two listboxes in my form (1)
Brd_Name and (2)Brd_Type. My aim is when the user selects a Brd_Name from
the listbox, populate the Brd_Type with corresponding Brd Type values.
For eg: For Brd_Name: ATU, Brd_Types: ATU_32G, ATU_32T
For Brd_Name:MCU, Brd_Types:MCU_CS, MCU_MS
Etc
In the onchange event of Brd_Name I wrote the following code
===============CODE=============
function Brd_Name_onchange() {
var brdName;
brdName = this.FORM1.Brd_Name
[this.FORM1.Brd_Name.selectedIndex].value; //Get the value selected in Brd
Name
if (brdName == "ATU"){
clearList(this.FORM1.Brd_Type);
this.FORM1.Brd_Type.Options[0] = new Option
("ATU_32G","ATU_32G");
this.FORM1.Brd_Type.options[1] = new Option("ATU_32T","ATU_32T");
}
else if (brdName == "MCU"){
clearList(this.FORM1.Brd_Type);
this.FORM1.Brd_Type.Options[0] = new Option("MCU_CS","MCU_CS");
this.FORM1.Brd_Type.options[1] = new Option("MCU_MS","MCU_MS");
}
this.FORM1.Brd_Type.Options[0].selected=true;
return true;
}
function clearList(ctrl){
// This function clears out the contents of a list box
for (var i = ctrl.options.length; i >=0; i--){
ctrl.options[i] = null;
}
ctrl.selectedIndex = -1;
}
=========CODE======
Now everytime I run this code I get the
error "this.FORM1.Brd_Type.options' is null or not an object
Can someone pls tell me where I am making the mistake..Is it not possible
to do this.
Any help is appreciated..I have already spend a lot of time on this and am
kinda desperate for an answer
TIA
---
Improve your web design skills with these new books from Glasshaus.
Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
r-20