简体   繁体   中英

how to select select2 using another select2 values

I have two select2 input boxes, My requirement is if I selected one select2 box that value will effect with another select2 box.

my code is as below:

<input class="select2-offscreen itemid_0" type="text" name="itemid" id="itemid[]" style="width:100px; left:297.5px !important; top:863px !important; float:left !important" tabindex="-1" onchange="display();">

<input class="select2-offscreen unitId_0" type="text" name="unitId" id="unitId[]" style="width:100px; left:297.5px !important; top:863px !important; float:left !important" tabindex="-1">


<script>
 function display(){
$(".unitId_0").select2("val","hr");
}
</script>

please tell me where I did mistake?

Thanks, Madhuri

You mean the value in both boxes should be same, right?

$(function () {
    $(".itemid_0").keyup(function () { // on key up in first box
        var value = $(this).val();     // get its value
        $(".unitId_0").val(value);     // set the value of the second box to it
    });
});

DEMO

这是您要找的吗?

 $('.unitId_0').val("hr");

you can do this like,it should work.

var a=$(".itemid_0").val();
$('.unitId_0').val(a);

you can use keyup or onclick events

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM