SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Custom User Title v1.0 FireFly's Avatar
    Join Date
    Aug 2001
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [XUL] Dynamically populating a <listbox>

    Hi,

    I am trying to dynamically populate a <listbox> object in XUL. I have a requireScript('foo.js') function that executes the JavaScript in foo.js, and that part works (100%). In fact, the list items are also added to the document... but in the wrong place. They appear at the very end of the document, and not inside the list box as they should (see attachment). At first I thought it was being added to the list box but "out of it", but I added a label directly below the box so you can see that the items are simply tacked to the end of the document. The box itself is very simple:

    Code:
    <listbox id="condo-list" flex="1" onselect="loadCondo(this.selectedItem.value);">
       </listbox>
    I have tried adding <listcols> and <listhead> to it to no avail.

    This is the JavaScript that gets executed:
    Code:
    var boxObj = document.getElementById('condo-list');
       
      var itemObj3 = document.createElement('listitem');
      itemObj3.setAttribute('value', 3);
      itemObj3.setAttribute('label', '12  FF');
      boxObj.appendChild(itemObj3);
    Where the last block repeats itself for every condo (3 is the ID of the condo in the example, it changes for each one). No errors appear in the console.

    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.
    Attached Images Attached Images

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    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 :::

  3. #3
    Custom User Title v1.0 FireFly's Avatar
    Join Date
    Aug 2001
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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>.

  4. #4
    Custom User Title v1.0 FireFly's Avatar
    Join Date
    Aug 2001
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doh, stupid me! The window itself is named "condo-list". It works great now. Thanks for the nudge adios.

  5. #5
    Custom User Title v1.0 FireFly's Avatar
    Join Date
    Aug 2001
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •