omrakhur omrakhur - 1 year ago 95
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];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download