Want to get details from database in laravel project according to user selection, for this have created a drop-down list from where the user selects any id which is further sent to javascript. Here is laravel code:
<div class="form-group">
<label class="col-lg-2 col-sm-2 control-label">Select Teacher</label>
<div class="col-lg-10">
<select class="form-control select2" name="teacher" id="teacher" onchange="teacherFunction()" required autofocus>
<option value="null">Select Teacher</option>
@foreach($users as $user)
<option value="{{$user->id}}">{{$user->name}}</option>
@endforeach
</select>
<p class="help-block"></p>
</div>
</div>
this is working fine and data is being sent to java-script function:
Here is javascript code:
function teacherFunction(){
var output = document.getElementById('teacher').value;
console.log(output);
var test = Number(output);
console.log();
console.log(test);
document.getElementById('output').innerHTML = '@foreach($users as $user) @if($user->id == '+1+') Test @endif @endforeach';
}
in this when output is being sent via innerHTML is i use id hard coded its working fine when i use the output value which user have selected then the if condition is not working. Have tried:
JSON.stringify()
JSON.parse()
parseINT()
Number()
All these didn't worked. Any Solution for this will be appreciated.