javascript - In dropdown list, onchange function is works only when change in the first item ? -


this html code list item database using foreach loop:

 <select class="form-control select" id="inventoryitem" name="inventoryitem" onchange="getunit();">      <option>---select item---</option>      <?php foreach($item $i) { ?>       <option><?php echo $i->name; ?></option>      <?php } ?>  </select> 

this script code:

function getunit() {   var item = $('#inventoryitem').val();   alert(item); } 

please remove onchange="getunit();" select , try code below:

$( "#inventoryitem" ).change(function() {   var item = $( "#inventoryitem option:selected" ).text();   alert(item); }); 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -