Listbox - select one item only

Questions related to using nuBuilder Forte.

Listbox - select one item only

Postby toms » Wed Jan 31, 2018 6:11 pm

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."
toms
 

Re: Listbox - select one item only

Postby admin » Thu Feb 01, 2018 4:16 am

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
blur.PNG (16.23 KiB) Viewed 764 times



Steven
admin
Site Admin
 
Posts: 3154
Joined: Mon Jun 15, 2009 9:53 am

Re: Listbox - select one item only

Postby toms » Thu Feb 01, 2018 5:13 am

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');
toms
 

Re: Listbox - select one item only

Postby admin » Thu Feb 01, 2018 5:14 am

toms,

Yes, that's a better answer.

Steven
admin
Site Admin
 
Posts: 3154
Joined: Mon Jun 15, 2009 9:53 am


Return to General