Topic: multiselect only submits one value

grtps free asked 3 years ago


Hello,

I wanted to select and submit multiple values from a multiselect. But only one selected value gets submited .

Javascript

$(document).ready(function() {
$('.mdb-select').materialSelect();
});

html used

<div class="row">
  <div class="col-md-12">

    <select name="country" class="mdb-select colorful-select dropdown-primary md-form" multiple searchable="Search here..">
      <option value="" disabled selected>Choose your country</option>
      <option value="1">USA</option>
      <option value="2">Germany</option>
      <option value="3">France</option>
      <option value="4">Poland</option>
      <option value="5">Japan</option>
    </select>
    <label class="mdb-main-label">Label example</label>
    <button class="btn-save btn btn-primary btn-sm">Save</button>

  </div>
</div>

For example if I select Poland and Japan only the value japan will be submitted for the field country. So how do I get the values of each option ? Expected behaviour was to have 4 and 5 submitted as values for Poland and Japan.


Krzysztof Wilk staff answered 3 years ago


Hi!

Try to use this code:

 $(document).ready(function () {
    $(".mdb-select").materialSelect();
    $(".dropdown-content li").click(function () {
      console.log($(".md-form input").val());
    });
  });

$(".md-form input").val() - that's the value you want to get, it returns all of selected options. Your result should display in the console for now, but feel free to replace console.log() with every code you want :)

Best regards



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.19.1
  • Device: pc
  • Browser: firefox
  • OS: windows 10
  • Provided sample code: No
  • Provided link: No