i have a dropdownlist (asp.net control) and a listbox control and a Add button
when the user select the item from dropdownlist and click on add button to add to the listbox.
how can i prevent the user from adding duplciate items and alert saying its already in the listbox?
UPDATE:
in my particular scenario, i have a dropdwonlist and adding the item to listbox both are asp.net controls and i am adding the items from code-behind and your solution is pure on client side, is there a way i can read the listbox and compare and alert the message?
Pretty easy. With this simple markup:
This would be the jQuery:
Check the fiddle: http://jsfiddle.net/mKFzz/
Edit: If you want to do it as per @ryangavin’s suggestion, here is the fiddle: http://jsfiddle.net/baLZN/