Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

321
Views
Laravel 8 Relleno automático después de seleccionar el valor en el menú desplegable

vuelvo a tener problema..

si seleccioné la ruta banjarmasin-jakarta, el campo biaya pelayaran llenará 1.750.000

Pero, quiero seleccionar nuevamente "cari rute pelayaran" y el campo biaya pelayaran llenará 0

seleccionado "cari rute pelayaran" para llenar 0 en el campo biaya pelayaran

esta es mi vista

 <select class="form-control select2bs4" id="biaya_pelayaran_id" name="biaya_pelayaran_id" style="width: 100%;"> <option value="">Cari Rute Pelayaran</option> @foreach ($biaya_pelayaran as $item) <option value="{{ $item->id }}"> Rute: {{ $item->rute_asal }} - {{ $item->rute_tujuan }} || Unit: {{ $item->unit->nama }} || Biaya: {{ number_format($item->biaya_pelayaran) }} </option> @endforeach </select> <div class="col-md-4"> <div class="form-group"> <label for="biaya_kapal">Biaya Pelayaran</label> <input type="number" class="form-control" id="biaya_kapal" name="biaya_kapal" value="0" readonly> </div> </div>

mi codigo ajax/javascript

 $('#biaya_pelayaran_id').change(function() { var id = $(this).val(); var url = '{{ route('getBiayaPelayaran', ':id') }}'; url = url.replace(':id', id); $.ajax({ url: url, type: 'get', dataType: 'json', success: function(response) { if (response !== null) { $('#biaya_kapal').val(response.biaya_pelayaran); } } }); });

controlador

 public function getBiayaPelayaran($id = 0) { $data = BiayaPelayaran::find($id); echo json_encode($data); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

reemplace su código ajax/javascript con esto, puede funcionar

 $.ajax({ url: url, type: 'get', dataType: 'json', success: function(response) { if (response !== null) { $('#biaya_kapal').val(''); $('#biaya_kapal').val(response.biaya_pelayaran); } } });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!