...

View Full Version : Adding Elements to a select element on an html form, using javascript



gwarden
04-04-2006, 06:01 PM
Ok, I'm trying to set my page up with 3 drop down lists in such a way that selecting one option in one controls what is available in the next one and so on, however, though I know how to clear a select object, I don't know how to add new elements. I am aware of the .add method but I can't figure out how to use it.
Here's what I have so far
function generateVersionsListForProject(proj, ver)
{
var x=document.getElementById(ver);
var y=document.getElementById(proj);
x.disabled=false;
for (i=0;x.length>0;i++)
{
x.remove(0);
}
switch(y.selectedIndex)
{
case 1:
add items;
break;
...
default:
x.disabled=true;
break;
}
}
obviously proj is the Id of the parent select and ver is the one that is depenent on it. The first part clears the list, that much I know works.
Not sure it matters but this script will eventually be dynamically generated by a .cgi page such that it will always clear, but then it will add different items depending on what was selected in proj. In theory this will be called in the onchange event.

Kravvitz
04-05-2006, 07:42 AM
http://www.quirksmode.org/js/options.html

mlanka
04-11-2006, 11:16 AM
http://www.mredkj.com/tutorials/htmljs.html



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum