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

273
Views
How to show selected value using javascript in laravel

i want to show the selected value to the select option, the value actually selected but cannot show that value on select option form. for example i have a 3 value it can be choose is anyaman, cendana, and bakulan. when 1 edit that form with value cendana, the showed value is the first sequence (anyaman) but when i open that select option that focused on the true data value (cendana).

This is HTML Script :

<div class="mb-1">
     <label class="form-label" for="user-role">Asal Kelompok</label>
       <select id="editkelompok_id" name="kelompok_id" class="select2 form-select">
         <option disabled="" value=""> <b> Pilih asal kelompok </b></option>
            @foreach($kelompok as $data)
              <option value="{{$data->id}}">{{$data->nama_desa}} - {{$data->nama_kelompok}} </option>
            @endforeach
       </select>
 </div>

The Controller

public function detaildataanggota($id)
{
    $status = anggota::findOrfail($id);
    return $status;
}

Java Script

    <script type="text/javascript">
    function detaildataanggota(id){
    $.ajax({
      url: "{{url('admin/pendataan/dataanggota/detail')}}" + "/" + id,
      dataType: "json",
      success: function(status) {
        $('#editid').val(status.id);
        $('#editnama_anggota').val(status.nama_anggota);
        $('#editnik').val(status.nik);
        $('#editjabatan').val(status.jabatan);
        $('#editjenis_kelamin').val(status.jenis_kelamin);
        $('#edittanggal_lahir').val(status.tanggal_lahir);
        $('#editalamat').val(status.alamat);
        $('#editkelompok_id').val(status.kelompok_id);
    },
});
}
</script>

The problem is on #editkelompok_id

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try this

let select  = $('#editkelompok_id');
select.on('change',()=>{
    // Your stuff
  })

or

let options  = $('#editkelompok_id').children();

    options.each(function() {
        let option = $(this);
        option.on('change', () => {
            select.val(option.val());
        })
    })

I hope it was useful

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!