Hi Stuart,
1) document.getElementById is not crossBrowser compatible -- it will
be recognized only by version 5+ browsers.
2) if you want to change a specific option's value/text, the following
is sufficient:
function doit(selObj, ndx)
{
txt = 'a'
selObj.options[ndx].text = txt;
selObj.options[ndx].value = txt;
}
<form name='a'>
<select name="b" onchange="alert(this.options[this.selectedIndex].value)">
<option value='0'>1</option>
<option value='1'>2</option>
<option value='2'>3</option>
</select>
<input type="button" onclick="doit(this.form.b, 2)">
</form>
3) if you want to remove an option, you either set that index to null
selObj.options[0] = null
or set the options.length to some number
selObj.options.length = 0;
4) if you wish to append new options, you need to use the new Option()
constructor. see the selection list script/tutorials at my GrassBlade
Javascript site:
http://members.aol.com/grassblad
Vinny
[color=blue]
> "Christopher Benson-Manica" <ataru@nospam.cyberspace.org> wrote in message
> news:bn639g$de9$1@chessie.cirr.com...[color=green]
> > I'm trying to dynamically change the contents of a select box by doing the
> > following...
> >
> > function myfunc() {
> > var obj=document.getElementById("objname"); // name of the select box
> > var str='';
> > str+='<option>blah</option>';
> > obj.innerHTML=str;
> > alert(obj.innerHTML);
> > }
> >
> > For reasons I don't understand, the alert gives me 'blah</option>'. Where[/color]
> is[color=green]
> > the leading <option> tag?
> >
> > --
> > Christopher Benson-Manica | I *should* know what I'm talking about - if I
> > ataru(at)cyberspace.org | don't, I need to know. Flames welcome.[/color][/color]