May 10, 2017
0
Level 1
Laravel recover cheakbox value when cheaked to php in the same page
Hi i m working with laravel ,My database containt a table of students.
i show students as radio button contain name as label and ID as value,
@foreach ($student as $s)
{!!Form::label($s->id,$s->name.' :')!!}
<input type="radio" name="student" onclick="cli();" value={!!$m->id!!}>
@endforeach
and i am trying to find a way that every time i cheak a radio button i get the Value (ID of student) then i show his informations
so i create a javascript function
function cli(){
var studentID=document.querySelector('input[name="student"]:checked').value;
alert(studentID);
var xhr = new XMLHttpRequest();
xhr.open("GET","Etd/"+a, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send();
}
Route:
Route::get('etd/Etd/{ID}', function($ID) {
return Response::json($ID);
});
what i want to do is to return ID to the same view and use it as PHP variable to find the student to show
@foreach ($student as $s)
@if($s->id==$ID)
--- show student informations ----
@endif
@endforeach
So how could i return ID to the same view and use it as PHP variable to decide the student to show ??
Please or to participate in this conversation.