Bootstrap Dual listbox and single select with fetching values in alert with add/delete/close option in jquery

后端 未结 1 1482
不思量自难忘°
不思量自难忘° 2021-01-17 00:41

Can you please anyone help me how to solve this issue.

Bootstrap have dual listbox option with single/multiple select only.

I need dual listbox with single s

相关标签:
1条回答
  • 2021-01-17 01:24
    //Html
    <select id="sel1">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
    </select>
    <select id="sel2"></select>
    //This is the JS
    //On change of the first select
    $('#sel1').on('change', function (e) {
        e.preventDefault();
        var selVal = $(this).val();
        var selHtml = $(this).find('option:selected').text();
        moveItem('#sel1', '#sel2', selVal, selHtml);//call our function
    });
    //On change of the second select
    $('#sel2').on('change', function (e) {
        e.preventDefault();
        var selVal = $(this).val();
        var selHtml = $(this).find('option:selected').text();
        moveItem('#sel2', '#sel1', selVal, selHtml);//call our function
    });
    //Move function take 4 parameters
    function moveItem(moveFrom, moveTo, selVal, selHtml) {
        if (confirm("Are you sure? : " + selVal)) {//Confirm dialogue box comes up and on selecting 'ok' this part will be executed
            $(moveTo).append('<option value="' + selVal + '">' + selHtml + '</option>');//append a value to select
            var mId = moveFrom + ' option[value="' + selVal + '"]';
            $(mId).remove();//remove value from the other select
        }
        return false;
    }
    
    0 讨论(0)
提交回复
热议问题