I have a list of competitions in my select option,
I need to know how can make this functionality work,
When a user selects a competition the page should reload with the competition data,
This is the select option in my blade
<div class="row pt-3">
<div class="col">
<select name="competition" id="competitionSearch" class="select listing pt-2 pb-2" >
<option value="">Select Competition</option>
@foreach ($allCompetitions as $competition)
<option value="{{ $competition->id }}"> {{ $competition->name }}</option>
@endforeach
</select>
</div>
</div>
this is how it looks like
this is the ajax get method i have used
$(document).ready(function(){
$('#competitionSearch').change(function(){
var compid = $(this).val();
if(compid > 0){
fetchRecords(compid);
}
});
});
function fetchRecords(id){
$.ajax({
url: 'detailed-registrations/getCompetitionAjax/'+id,
type: 'get',
success: function(response){
if (response) {
//load selected competition here
}
}
});
}
My routes
Route::get('competitions/{competition}/detailed-registrations/getCompetitionAjax/{id}','CompetitionController@getCompetitionAjax');
My function in the controller
public function getCompetitionAjax($competition, $id, Request $request)
{
$comp = $this->competitionsRepo->findOrFail($id);
return redirect(route('competitions.detailed-registrations',$id))->with('comp',$comp);
}
I need to know how can i make this functionality work
initially the user will be in a competition page
http://127.0.0.1:8000/competitions/1/detailed-registrations
once he selects the competition 2 redirected to the competition page with the filtered query parameters as
http://127.0.0.1:8000/competitions/2/detailed-registrations?filters=visible&age=all&gender=all
Don't think you need an ajax call for redirecting the user to a different page when a competition is selected, you can redirect from javascript
$(document).ready(function(){
$('#competitionSearch').change(function(){
var compid = $(this).val();
if(compid > 0){
//Redirect the user to the page which will show the selected details
location = 'competitions/' + id + '/detailed-registrations?filters=visible&age=all&gender=all';
}
});
});
And then let the Laravel controller method handle the request to the route competitions.detailed-registrations
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Laravel is a free open source PHP framework that came out in 2011. Since then, it has been able to become the framework of choice for web developers. One of the main reasons for this is that Laravel makes it easier, faster, and safer to develop complex web applications than any other framework.
https://laravel.com/
JavaScript is a multi-paradigm language that supports event-driven, functional, and mandatory (including object-oriented and prototype-based) programming types. Originally JavaScript was only used on the client side. JavaScript is now still used as a server-side programming language. To summarize, we can say that JavaScript is the language of the Internet.
https://www.javascript.com/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.