Home > other >  Laravel Livewire Autofill Input Box Based On Drop Down Selection
Laravel Livewire Autofill Input Box Based On Drop Down Selection

Time:11-11

I am asking for help. Is there any way I could fill an input box based on drop down selection? On my modal I have a dropdown option for subject description and I would like the subject number input field dynamically change its value. Any help would be much appreciated.

This is how I retrieved the data for my dropdown

subjects=DB::table('programs_subj')->select('corsdes', 'corsno')->get()

This is my dropdown code for the subject description which is working and the selected is saved but I could quite how to incorporate the subject number

   <select name="corsdes" id="corsdes" wire:model="corsdes">
          <option value="corsdes" wire:model="corsdes"></option>
          @foreach($subjects as $sbj)
          <option value="{{ $sbj->corsdes }}">{{ $sbj->corsdes}}</option>
            @endforeach
        </select>
<input name="corsno" id="corsno" wire:model="corsno"><input>

CodePudding user response:

if you have the public properties $corsdes and $corsno then:

public function updatedCorsdes($value)
{
   $this->corsno = $this->subjects->where('corsdes',$value)->first()->corsno;
}
  • Related