Page 1 of 1

Listbox - select one item only

Posted: Wed Jan 31, 2018 9:41 am
by toms
Hi,

I want the user to select only one item at the same time in a select object (listbox). How do I disable the multiple selection? Is there an inbuilt way to do this?

Basically it's an object (Type: Select) with Multiple: Yes (by setting this, I see more than one item at a time) but without the attribute "multiple."

Re: Listbox - select one item only

Posted: Wed Jan 31, 2018 7:46 pm
by admin
toms,

Try this...

Code: Select all

function stop_multiple(t){

   var s = $("#" + t.id).val();

   for(var i = 1  ; i < s.length ; i++){
       $("#" + t.id + " option[value='" + s[i] + "']").remove();
   }

}

blur.PNG

Steven

Re: Listbox - select one item only

Posted: Wed Jan 31, 2018 8:43 pm
by toms
Steven,

Thanks for the response. In the meantime, I have figured out another way by removing the multiple="multiple" attribute and adding a size.
By doing this, you can't select more than one item.

Code: Select all

$('#myselect').removeAttr('multiple');
$('#myselect').attr('size','5');

Re: Listbox - select one item only

Posted: Wed Jan 31, 2018 8:44 pm
by admin
toms,

Yes, that's a better answer.

Steven