Many time we insert same time more than once into the list-box so to avoid this following code is used which show appropriate message if user is going to insert same message more than once.
/*Here 'IncludedList' is listbox Id*/
var included1 = document.getElementById('IncludedList');
var optionsCount = included1.options.length;
for (var i = 0; i < optionsCount; i++) {
//check text
var data = included1.options[i].text;
or
//check value
var data = included1.options[i].val();
if (data == currentState) {
flag = 1;
alert("Item already Included");
break;
}
}
/*Here 'IncludedList' is listbox Id*/
var included1 = document.getElementById('IncludedList');
var optionsCount = included1.options.length;
for (var i = 0; i < optionsCount; i++) {
//check text
var data = included1.options[i].text;
or
//check value
var data = included1.options[i].val();
if (data == currentState) {
flag = 1;
alert("Item already Included");
break;
}
}
No comments:
Post a Comment