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
Post a Comment