assign values to input from selected ID of a select2

0

I hope you can help me, I'm new to this. I need that when selecting an input from a select2, show me the cost and the unit of measurement of the selected input in their corresponding input, in this case the inputs "unidadI_P" and "costoI_P".

this is my bucket

<div class="col-xs-12 col-md-5 col-lg-5">
  <label for="nameP" class="col-form-label text-md-right">{{ __('Elegir insumo') }}</label>
  <div class="form-group" id="selectInsumo">
      <select class="form-control select2" name="select_insumoP" id="select_insumoP" style="width: 100%;" data-style="btn-default">

        @foreach ($insumo as $Insumos)
          <option value="{{ $Insumos['id'] }}"> {{ $Insumos['nombreI'] }}</option>
        @endforeach
      </select>
  </div>
</div>

<div class="col-xs-12 col-md-2 col-lg-2">
    <label class="col-form-label text-md-right">{{ __('Unidad de medida') }}</label>
    <input type="input" id="unidadI_P" name="unidadI_P" class="form-control" disabled value=""></input>
</div>

<div class="col-xs-5 col-md-2 col-lg-2">
    <label class="col-form-label text-md-right">{{ __('Costo') }}</label>
    <input type="number" id="costoI_P" name="costoI_P" class="form-control" disabled value="">
</div>

this is my controller

class productosController extends Controller
{

    public function __construct()
    {
        $this->middleware('auth');
    }


    function viewadminProducto() 
    {

        $insumo = Insumos::all();
        return view('Productos.adminProducto', compact('insumo'));

    }

}

and finally, this is my model

class Insumos extends Model
{
    protected $fillable = ['nombreI', 'UmedidaI', 'cantidadI', 'costoI','categoriaI', ];
}

From what I understand, it can be done with Jquery ajax, but I have not been able to achieve it ... please help

    
asked by KilzaNiko 08.11.2018 в 23:46
source

0 answers