Issue
I want to pass the selected radio button value as a parameter with Laravel route.
My Route is:
Route::resource('/datas','DataController');
From this route, I am aiming to call localhost:8000/datas/{data}
My data.blade.php is:
<form id="dataform" action="{{ route('datas.show')}}" method="GET">
<table class="table">
<tr>
<th>Select bullet</th>
<th>SL NO</th>
<th>Name</th>
<th>Age</th>
</tr>
@foreach ($datas $key => $data)
<tr>
<td><input type="radio" id="data{{$data->id}}" name="data" value={{$data->id}}></option></td>
<td>{{$key}}</td>
<td>{{$data->name}}</td>
<td>{{$data->age}}</td>
</tr>
@endforeach
</table>
<button type="submit" id="edit_submit" class="btn btn-default">Show</button> </form>
My show function will be...
public function show($id)
{
//Code to showing data and redirect to show page
}
I want to get value of this radio button(given below).
<td><input type="radio" id="data{{$data->id}}" name="data" value={{$data->id}}>
and include it as a parameter with the Form action below
<form id="dataform" action="{{ route('datas.show')}}" method="GET">
Solution
I have made some changes to this code. Changed button to anchor tag. So my blade.php is:-
<table class="table">
<tr>
<th>Select bullet</th>
<th>SL NO</th>
<th>Name</th>
<th>Age</th>
</tr>
@foreach ($datas $key => $data)
<tr>
<td><input type="radio" id="data{{$data->id}}" name="data" value={{$data->id}}></option></td>
<td>{{$key}}</td>
<td>{{$data->name}}</td>
<td>{{$data->age}}</td>
</tr>
@endforeach
</table>
<a href="javascript:showfunction()" id="showlink" class="btn btn-default">Show</a>
and I added a javascript function too.
<script>
function showfunction(){
var id = document.querySelector('input[name = "data"]:checked').value;
var url = '{{route("admin.questions.show",":id")}}';
url=url.replace(':id',id);
document.location.href=url;
}
</script>
Answered By - Hisham U Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.