Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I made multiple selection on the dropdown but in Javascript alert, showing 1 value only

I add multiple on my dropdown list. But, when I check the values via Javascript with alert, it just showing the first one that I selected.

<label class="control-label col-sm-4" for="affectedwaferid" style="margin-left: 1px;">Affected Wafer ID :</label>
           <div class="col-sm-4">
            <p class="form-control-static" style="margin-top: -6px;">
                
                <select class="form-control" id="affectedwaferid" name="affectedwaferid" multiple>
                <option value="" selected > Select Quantity</option>
                
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
                
              </select>
            </p>
          </div>

Below is Javascript.
var affectedwaferid = document.translot.affectedwaferid.value;

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As I posted in the comment,in order to get the multiple selected values, you need to use selectedOptions instead

function showSelected(){
  var options = document.getElementById('affectedwaferid').selectedOptions;
  var values = Array.from(options).map(({ value }) => value);
  document.getElementById("selected-result").innerHTML = values; 
}
<label class="control-label col-sm-4" for="affectedwaferid" style="margin-left: 1px;">Affected Wafer ID :
  <span id="selected-result"></span>
</label>
<div class="col-sm-4">
  <p class="form-control-static" style="margin-top: -6px;">

      <select class="form-control" id="affectedwaferid" name="affectedwaferid" multiple onchange="showSelected()">
      <option value="" selected > Select Quantity</option>

      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
      <option value="6">6</option>

    </select>
  </p>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading