technofreaks's avatar

Help! Form auto-completing Inter dependent select fields

Hello..

Struggling to create auto complete forms, where selecting one of the dropdown auto completes other related fields.

Form has 3 Input fields, which are drop down select fields, When User selects Employee number or phone number (any of one) form auto fills First-Name, Last-Name and email (3 fields are view purpose only non editable.)

Controller:

$employee_numbers = VesselData::pluck('employee_number', 'id');
first_names = VesselData::pluck('first_name', 'id');
$phonenums = VesselData::pluck('phone', 'id');
return view('fieldworkcreate', compact('employee_numbers', 'first_names', 'phonenums' ));

View Blade file fieldworkcreate is a form to fetch employee data from existing records, then update office, work location. Saving form will save to table 2. Employee list already populated in database.

Table 1 - Employee:
ID  EMPNUM  FIRSTNAME  LASTNAME PHONE   EMAIL
1    007     JANE        DOE    001007  janedoe@
Table 2 - FieldworkData
ID  EMPID  DEPARTMENTID  OFFICELOCID ONSITE
1    1      2                  3        0

Thank You Suds

0 likes
2 replies
technofreaks's avatar

Tried this using jquery, looking for example with out jquery, using laravel livewire

HTML

<select id="regnum">
    <option value="1">007</option>
    <option value="2">005</option>
    <option value="3">003</option>
</select>

<select id="fname">
    <option value="1">James</option>
    <option value="2">Jane</option>
    <option value="3">John</option>
</select>

Jquery

$('#regnum').click(function () {
    $('#regnum option:selected').each(function () {
    console.log($(this).val());    
    var vregnum = $(this).val();
    $("#fname option[$vregnum]").attr('selected', true); 
});

});

Please or to participate in this conversation.