Domanda

i have two controls one chosen multiselect and another select2 multivalue select

chosen multiselect

<select id="mlti_1" class="chosen span6" multiple='multiple' >
  <option value="1">one</option>
  <option value="2">two</option>
  <option value="3">three</option>
</select>

jquery multi value select

<select id="mult_2" class="select2 span6" multiple='multiple'>
  <option value="1">ONE</option>
  <option value="2">TWO</option>
  <option value="3">THREE</option>
</select>

both controls are working fine, but the problem is when i am passing these Ids to JS function and trying to display it's type both are showing the type as select-multiple

JS

//no need to initiate chosen multiselect
$('#mult_2').multiSelect(); // initiating select2 multiselect
function displayType(id) // id = mult_val or drp_me
{
  var control=document.getElementById(id);
  console.log(control.type); // both controls showing as select-multiple
}

i am using jquery plugins for both controls. basically both are same select control (select). but physically they are different. how i can differ these controls through code?? is there any solution for this? This is the screen shots of the controls

È stato utile?

Soluzione

By differ if you meant accessing them and their values using different handles, you can do that just by accessing their ids.

use $("#mlti_1") for accessing the chosen control and $("#mult_2") for the second multiselect control.

UPDATE :

As I said in the comment, you can use the following function to determine the type of the multi-select.

function displayType(id) // id = mult_val or drp_me
{
    var control = document.getElementById(id);
    console.log(control.type); // both controls showing as select-multiple
    if (control.classList.contains("chosen")) {
        console.log("chosen");
    } else if (control.classList.contains("select2")) {
        console.log("select2");
    }
}

provided, you assign proper class names(chosen and select2) to the various multi-selects in the HTML code.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top