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

312
Views
Laravel 8 Auto fill after selecting value on dropdown

i problem again..

if i selected rute banjarmasin-jakarta, biaya pelayaran field will fill 1.750.000

But, i want to selected again "cari rute pelayaran" and biaya pelayaran field will fill 0

selected "cari rute pelayaran" to fill 0 in biaya pelayaran field

this my view

<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>

my ajax/javascript code

 $('#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);
                }
            }
        });
    });

controller

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

replace your ajax/javascript code with this it may work

    $.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!