0

I tried to make multiple selection on the dropdown list but it just recognized as the first one that was chosen. Is there anyway to fix it?

var affectedwf = document.translot.affectedwaferid.options[document.translot.affectedwaferid.selectedIndex].value;

Above code is javascript.

<div id="afwid">
  <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>
            <?php  
            echo $cbo_oorigsite;
            ?>
          </select>
        </p>
      </div>

$affwf = array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25");

for($i=0;$i<count($affwf);$i++) {
    $selected = ($affwf[$i] == $affectedwf)? "selected" : "";
    $cbo_oorigsite .= "<option value=\"" . $affwf[$i] . "\" " . $selected . ">" . $affwf[$i] . "</option>";
}
  • You've to iterate through the options, and check `selected` property of each option. – Teemu Nov 07 '22 at 07:05
  • How can I solve it? – Travis Sloap Nov 07 '22 at 07:09
  • That depends on how you need to present the values, push the selected values into an array or object, create a string of them, or what ever you need. – Teemu Nov 07 '22 at 07:12
  • [This has been asked before](https://stackoverflow.com/a/63378114/1169519). Consider also to rename `select` element, see https://stackoverflow.com/a/17927248/1169519 . – Teemu Nov 07 '22 at 07:42

0 Answers0