John
John

Reputation: 147

jQuery Chose plugin how to remove selected item from drop down

I im using jquery choose plugin that is using two input boxes when page loads...and a need like in this example when i select number 1 in first box that this number is removed from second input box....this works fine...but problem is when i add dynamically input box i can't get item number 1 removed from added dynamic input box.

So question is: how can i remove selected values from input box when selecting other input boxes that is added dynamically and selected items in each select box is not visible in all selected box that exists and is added dynamically?

Here is jsfiddle:

[http://jsfiddle.net/dq97z/640/][1]

And here is picture what i need:

enter image description here

Upvotes: 0

Views: 105

Answers (1)

Seano666
Seano666

Reputation: 2238

Maybe this will help you out
http://jsfiddle.net/s9r73qjm/

   //an array to save selections
 var selectedVals = [];
//push to the array when we have selected
selectedVals.push(selectedValue);

//check on the values when building the drop down
$( "#btn_newrow" ).click(function() {
  var newList = document.createElement("select");
  newList.dataset.placeholder = "Number row 3";
  newList.style.width = "350px";
  var newListData = new Option("placeholder", "placeholder");
    for (var i = 0; i < 6; i++){
        if (selectedVals.indexOf(i.toString()) == -1){
        //then it hasn't been selected
      newListData = new Option(i.toString(), i.toString());
      newList.appendChild(newListData);
    }
        $( ".wrapper" ).append(newList);
    }

});

Upvotes: 1

Related Questions