Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] How can i create new <OPTION> elements of a visible <SELECT> el


  • From: javascript@xxxxxxxxxx (Bill Marriott)
  • Subject: [Javascript] How can i create new <OPTION> elements of a visible <SELECT> el
  • Date: Thu, 22 Nov 2001 06:51:23 +1100

Here is some code that may give you some ideas.
I use it to dynamically change the options in one select depending on the
choice (filter) of the other select.
the options for the select that changes are all stored in an array. ( 3 part
array , value, text and filter)
I call the function from the onchange event of the first select.

var filter = 0 ;
function setSelOptions()
{

 var sel1Obj = document.getElementById("firstselect");
 filter=sel1Obj.value;
 var sel2Obj = document.getElementById("secondselect");


 sel2Obj.options.length = 0;          //// clear out all the existing
options
 var i;
  for (i = 0; i < selArray.length; i++)
    {
        if (filter == selArray[i][2])


           var pOption=document.createElement("OPTION");
           pOption.value=selArray[i][0];
           pOption.text=selArray[i][1];
           sel2Obj.options.add(pOption);
          }
    }
}

good luck with the invisible part

Bill