PDA

Click to See Complete Forum and Search --> : add items to a combobox


Nina
Jun 26th, 2000, 11:03 PM
How do I add items to a combobox in a HTML doc with JavaScript?

the Combobox looks like this:

<SELECT id="select2" name="name2" style="HEIGHT: 22px; WIDTH: 142px">
<OPTION selected value="n/a"></OPTION>
</SELECT></P>


and here's the JavaScript function that I've got so far.
Depending on what item in another combobox the user clicked on, different items go into combobox2


function select1_onclick(val)
{
select2.clearAttributes;
switch (val)
{
case "n/a": select2.clearAttributes; break;
case "hs":

//add items to select2

break;
case "hm":

//add items to select2

break;
default:
break;
}
}


Any suggestions?
Thanks in advance, Nina

Mark Sreeves
Jun 27th, 2000, 02:50 AM
this code adds items to a <select> box using Javascript

Is this any use to you?




<BODY><HEAD>
<script Language="JavaScript">
var i;
function AddItem(){
i++;
var oOption = document.createElement("OPTION");
oOption.text="Apples";
oOption.value=i;
document.frm1.select1.add(oOption);
}
</script>
</head>
<form name="frm1">
<SELECT id=select1 name=select1 size=2 style="HEIGHT: 134px; WIDTH: 258px">


</SELECT>
</form>
<input type="button" onclick="AddItem()" value="Click">
</BODY>
</HTML>

Nina
Jun 27th, 2000, 02:43 PM
Thanks, Mark
That's just about what I need.