Results 1 to 5 of 5
May 1, 2004, 00:06 #1
[XUL] Dynamically populating a <listbox>
<listbox id="condo-list" flex="1" onselect="loadCondo(this.selectedItem.value);"> </listbox>
var boxObj = document.getElementById('condo-list'); var itemObj3 = document.createElement('listitem'); itemObj3.setAttribute('value', 3); itemObj3.setAttribute('label', '12 FF'); boxObj.appendChild(itemObj3);
Oh and before anyone mentions this, I know I can RDF datasources but I specifically can't in this case. I imagine it would be easier but it's not an option at the moment...
Update: It seems that the list items appear wherever I place the <script> bit, not necessarily at the end of the document. Perhaps I am using createElement() wrong?
Any help would be greatly appreciated.
May 1, 2004, 12:07 #2
- Join Date
- May 2003
- 0 Post(s)
- 0 Thread(s)
Just a quick guess: you might be missing some required nodes in your listbox tree; without them, new listitems might not append correctly. Or the browser might simply 'fill in' the missing nodes (as with thead, tbody), in which case you'd need to append to them, not the Listbox object. Check this reference. A DOM inspection would help.::: certified wild guess :::
May 2, 2004, 00:26 #3
Thanks adios, I will do a DOM check on the list box. If all else fails I might use a <tree> rather than a <listbox>.
May 2, 2004, 00:30 #4
Doh, stupid me! The window itself is named "condo-list". It works great now. Thanks for the nudge adios.
May 2, 2004, 00:51 #5
Stupid me, take 2. In case anyone will ever come across this thread, the listbox object has a function appendItem() that lets you add items to the box. First argument is the label of the new item, second argument is its value.