Well, its not an array.
Letâs say your combo is:
Code:
<select name="sel" id="sel">
<option value="01" selected>2001</option>
<option value="02" >2002</option>
<option value="03" >2003</option>
</select>
and you want to add â2004â on the end.
Further, letâs presume there are no CRs in the html, as I said before. (If you have spaces, CRs, tabs, whatever, Iâll let you do your own character counting...)
So then:
Code:
function Add_04()
{
var ctl = document.all["sel"]; // Set a reference to the control
var s = ctl.outerHTML; // Get its contents
s = s.substr(0, s.length - 9); // Get rid of the </select> on the end
s += "<option value="04">2004</option>"; // Add your new list item(s)
s += "</select>"; // Reconstruct the end of the html
ctl.outerHTML = s; // Put the string into the control.
}
Now your html would be:
Code:
<select name="sel" id="sel">
<option value="01" selected>2001</option>
<option value="02" >2002</option>
<option value="03" >2003</option>
<option value="04">2004</option></select>
(Note that because of the fairly primitive string handling, the new text went in right where the â</select>â
had been, and now â</select>â follows immediately after the last item in the list, with no formatting. The browser wonât care...)