omrakhur omrakhur - 10 months ago 48
jQuery Question

How to retrieve selected option's value in Laravel 5 dropdown list?

My dropdown list is prepopulated with names using a 'Users' table. I wish to use the selected name's id to then fill a table underneath the dropdown list with that person's email, also stored in the same 'Users' table. Any ideas on how I should do that while keeping everything safe?

My form:

<div class="form-group">
<label for="employee-select" class="control-label col-md-3">Select Employee</label>
<div class="col-md-8">
<div class="col-md-10">
{{Form::select('user',$users, null, ['placeholder' => 'Choose employee...', 'class'=> 'select-block-level chzn-select'])}}

The controller:

public function create()
$users = User::lists('name','id');

return View::make('sickleaves.create')->with('users',$users);



Answer Source
function updateText() {
        var empName=$('#userdropdown :selected').text();
        empName = empName.split(' ');

        document.getElementById("firstname").value = empName[0];
        document.getElementById("surname").value = empName [empName.length - 1];