Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Yassir's avatar

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 ??

0 likes
0 replies

Please or to participate in this conversation.