Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript bootstrap-multiselect get all selected values on button click

I want to get all selected values of bootstrap-multiselect on button click.

My JSP page code is given below

<script type="text/javascript">
    $(document).ready(function() {
        $('#ddlPermission').multiselect({
            buttonWidth : '100%',
            maxHeight : 100,
            includeSelectAllOption : true,
            dropRight : true
        });
    });

    function myFunction() {
        var allVal=$("ddlPermission").val();
        alert(allVal);
        return false;
    }
</script>
<body>
    <select id="ddlPermission" multiple="multiple" name="permission_ddl">
        <option value="A">A</option>
        <option value="B">B</option>
        <option value="C">C</option>
        <option value="D">D</option>
    </select>
    <input type="submit" name="btnSubmit" id="btnSubmit" onclick="myFunction()" class="button active" value="Submit">
</body>

I am using Java JSP.

like image 515
user3441151 Avatar asked Jul 07 '17 11:07

user3441151


1 Answers

Working fiddle.

You're missing the id sign # in the following line :

var allVal=$("ddlPermission").val();

Should be :

var allVal=$("#ddlPermission").val();

Hope this helps.

like image 124
Zakaria Acharki Avatar answered Sep 29 '22 07:09

Zakaria Acharki