Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if listbox is empty and...

Status
Not open for further replies.
May 13, 2005
56
US
When I click a button, I currently have a script that will move an item from one listbox to another.

What I would like to do is have this script move the item to one of 3 listboxes. I would like to know if there is a way I can check each box to see if they are empty, and move the item to the first available listbox with nothing in it??

Any ideas, is this possible..

Thank you,

Mike
 
check the length property of the options collection of each select list. zero means no options.


-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Im not sure I follow, I know that size=x if a solid varible, but length, does that work?

Thanks,

Mike
 
>I know that size=x if (sic is?) a solid varible, but length, does that work?
That's not very comprehensible. If frmtest is the form name, osel is the select element's name (as an illustration I used in a related thread of yours) then the checking is done like this.
[tt]
if (document.frmtest.osel.length) {
alert("The select element is empty.")
} else {
alert("The select element has "+document.frmtest.osel.length+" options available.")
}
[/tt]
 
Sorry, what I meant to say was:

I know that I can set the size attribute on these list boxes, but what is, or how can I set the length like was mentioned above.

Thanks for the code, i'll see what I can do with this..

Mike
 
tsuji,

i think you forgot the not operator:

Code:
    if ([highlight]![/highlight]document.frmtest.osel.length) {
        alert("The select element is empty.")
    } else {
        alert("The select element has "+document.frmtest.osel.length+" options available.")
    }

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top