lundi 25 mars 2019

Auto-fill in textbox based on select option

I am creating a table which when "Item" is selected, the description will be filled automatically based on select option.

I have referred to some other links like:

Auto fill field depending on the option selected

https://www.reddit.com/r/laravel/comments/adg9s5/make_a_text_box_automatically_fill_depending_on/

but none of them answer my question.

Here's my script

$('#item').change(function(e){
     var element = $(this).find('option:selected'); 
     var desc = element.attr("Description");
    $('#Description').text(desc);
    console.log(desc)

});

This is for the item

<select class="form-control select2" id="item" name="item">
<option value="" disabled selected>None</option>
@foreach ($deliveryitems as $items)
<option  value=""></option>
@endforeach
</select>

This is for the description

<input type="text" class="Description form-control" name="Description" id="Description" readonly>


This is my controller

$deliveryitems = DB::table('inventories')
        ->leftJoin('deliveryitem','inventories.Id','=','deliveryitem.inventoryId')
        ->select('inventories.Id','deliveryitem.formId','inventories.Item_Code','inventories.Description','inventories.Unit','deliveryitem.Qty_request')
        ->get();

How to auto fill in the item description based on the item selected from the select options?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire