Reputation: 1687
How do you check if a selectbox is empty with plain JavaScript and alert the user "The selectbox contains 0 items."
Upvotes: 2
Views: 17085
Reputation: 97672
if (document.getElementById('select').options.length == 0)
alert('The selectbox contains 0 items');
Upvotes: 6
Reputation: 1203
Use:
if (selectObject.options.length == 0) {
alert('The selectbox contains 0 items');
}
See http://www.w3schools.com/jsref/coll_select_options.asp
Upvotes: 0