How to get selected option value from multiple select using jQuery


username

I want to select selected value from multiselect dropdown, see jsfiddle

I tried a few ways but no success, can someone help me with this

<script type="text/javascript">
$(function(){
    $("select").multiselect({ 

        click: function(e){

        var abc =  $(this).multiselect("widget").find("input:checked");

        console.log(abc);
    }   
});

});
</script>
</head>

<h3>Basic</h3>
<p>
    <select title="Basic example" multiple="multiple" name="example-basic" size="5">
    <option value="option1">Option 1</option>
    <option value="option2">Option 2</option>
    <option value="option3">Option 3</option>
    <option value="option4">Option 4</option>
    <option value="option5">Option 5</option>
    <option value="option6">Option 6</option>
    <option value="option7">Option 7</option>
    <option value="option8">Option 8</option>
    <option value="option9">Option 9</option>
    <option value="option10">Option 10</option>
    <option value="option11">Option 11</option>
    <option value="option12">Option 12</option>
    </select>
</p>
Ekramul Hoque

try this code to get selected item

   <script>
    $( "select" )
      .change(function() {
        var str = "";
        $( "select option:selected" ).each(function() {
          str += $( this ).text() + " ";
        });
        $( "div" ).text( str ); // Put selected value to div
        console.log(str);
      })
      .trigger( "change" );
    </script>

Related


Get value of selected option from multiple select fields at once

username Imagine xhow many select fields (values xundetermined) there are. I want to use jQuery (or vanilla JavaScript) to get the value of the selected option for each select field. my method: var cars = $(".select").find("option:selected").val(); $(".select"

Get value of selected option from multiple select fields at once

username Imagine xhow many select fields (values xundetermined) there are. I want to use jQuery (or vanilla JavaScript) to get the value of the selected option for each select field. my method: var cars = $(".select").find("option:selected").val(); $(".select"

Get key value of selected option in select using jQuery

Tara I have a JSON like quarterJson = [{"quarter_id":1, "quarter":"Quarter 1", "end_date":'31.03.'}, {"quarter_id":2, "quarter":"Quarter 2", "end_date":'30.06.'}, {"quarter_id":3, "quarter":"Quarter 3", "end_date":'31.09.'},

How to deselect selected option in multiple select using jQuery

Sugumar venkatesan I want to deselect selected option in multiple select based on value of selected option i have tried jQuery removes the selected option from it, then jQuery remove option from select <select size="5" id="skills" multiple> <option value="0

How to deselect selected option in multiple select using jQuery

Sugumar venkatesan I want to deselect selected option in multiple select based on value of selected option i have tried jQuery removes the selected option from it, then jQuery remove option from select <select size="5" id="skills" multiple> <option value="0

How to set selected value in select option using jquery?

Fernando Paiva I have two selectand it has the same value, just the id is changed. What I want is to select the value in select one and then select the same value in the second select. what should I do? try //here get the value select in select1 (it works) var

How to set selected value in select option using jquery?

Fernando Paiva I have two selectand it has the same value, just the id is changed. What I want is to select the value in select one and then select the same value in the second select. what should I do? try //here get the value select in select1 (it works) var

How to set selected value in select option using jquery?

Fernando Paiva I have two selectand it has the same value, just the id is changed. What I want is to select the value in select one and then select the same value in the second select. what do I do? try //here get the value select in select1 (it works) var val

How to set selected value in select option using jquery?

Fernando Paiva I have two selectand it has the same value, just the id is changed. What I want is to select the value in select one and then select the same value in the second select. what do I do? try //here get the value select in select1 (it works) var val

How to set selected value in select option using jquery?

Fernando Paiva I have two selectand it has the same value, just the id is changed. What I want is to select the value in select one and then select the same value in the second select. what do I do? try //here get the value select in select1 (it works) var val

How to get selected option value from select inside div

zabi I have the following html code <div id="BrokersList4ServiceEndWrapper"> <select id="BrokersList4ServiceEnd"> <option value="1">s1</option> <option value="2">s2</option> </select> </div> I tried Set the selected value to 1. Get the value of the

How to get selected option value from select inside div

zabi I have the following html code <div id="BrokersList4ServiceEndWrapper"> <select id="BrokersList4ServiceEnd"> <option value="1">s1</option> <option value="2">s2</option> </select> </div> I tried Set the selected value to 1. Get the value of the

Get selected option text of SELECT using JQuery

Wasim I've created options dynamically, where all the values in the options come from a list of sharepoints. Now I want to get the text of the selected option. I have tried several ways but can't get Code to get data from list $("#ddlIncrementType").append(

Get selected option text of SELECT using JQuery

Wasim I've created options dynamically, where all the values in the options come from a list of sharepoints. Now I want to get the text of the selected option. I have tried several ways but can't get Code to get data from list $("#ddlIncrementType").append(

Get selected option text of SELECT using JQuery

Wasim I've created options dynamically, where all the values in the options come from a list of sharepoints. Now I want to get the text of the selected option. I have tried several ways but can't get Code to get data from list $("#ddlIncrementType").append(

Get selected option text of SELECT using JQuery

Wasim I've created options dynamically, where all the values in the options come from a list of sharepoints. Now I want to get the text of the selected option. I have tried several ways but can't get Code to get data from list $("#ddlIncrementType").append(

Multiple select boxes, get selected value using jQuery

Jim I have a grid and each row has a dropdown to select a state. What I want to do is after submitting the form, grab each selected value (skip if none) <select name="state" class="dd1"> <option value="0">Select A State (optional)</option> <option value="AL">A