0

I am trying to console values which I have selected multiple values from the dropdown, I have given the code below which I have tried.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/harvesthq/chosen/gh-pages/chosen.jquery.min.js"></script>
<link href="https://cdn.rawgit.com/harvesthq/chosen/gh-pages/chosen.min.css" rel="stylesheet" />

<select data-placeholder="Begin typing a name to filter..." id="mulValue" multiple class="chosen-select" name="test">
  <option value=""></option>
  <option value="American Black Bear">American Black Bear</option>
  <option value="Sloth Bear">Sloth Bear</option>
  <option value="Sun Bear">Sun Bear</option>
  <option value="Polar Bear">Polar Bear</option>
  <option value="Spectacled Bear">Spectacled Bear</option>
</select>
<input onclick=show() type="submit">


<script>
  $(".chosen-select").chosen({
    no_results_text: "Oops, nothing found!"
  })

  function show() {
    var a = document.getElementById("mulValue").value;
    console.log('aaaaaa', a)
  }
</script>

1 Answer 1

1

You can use jquerys val()

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/harvesthq/chosen/gh-pages/chosen.jquery.min.js"></script>
<link href="https://cdn.rawgit.com/harvesthq/chosen/gh-pages/chosen.min.css" rel="stylesheet" />

<select data-placeholder="Begin typing a name to filter..." id="mulValue" multiple class="chosen-select" name="test">
  <option value=""></option>
  <option value="American Black Bear">American Black Bear</option>
  <option value="Sloth Bear">Sloth Bear</option>
  <option value="Sun Bear">Sun Bear</option>
  <option value="Polar Bear">Polar Bear</option>
  <option value="Spectacled Bear">Spectacled Bear</option>
</select>
<input onclick=show() type="submit">


<script>
  $(".chosen-select").chosen({
    no_results_text: "Oops, nothing found!"
  })

  function show() {
    var a = $("#mulValue").val();
    console.log('aaaaaa', a)
  }
</script>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.