Reputation: 1
am creating an application in laravel were one can select an option from a form select and he'll be redirected to another form based on the option selected.The options are from my database.
<script type="text/javascript">
function submitForm() {
var selectedOption = $('#service').val();
var url = "";
if(selectedOption == '{{ $val->id }} = 1') {
url = '{{ route('all.academics')}}';
} else if (selectedOption == '{{ $val->id }} = 2') {
url = '{{ route('all.it')}}';
} else (selectedOption == '{{ $val->id }} = 3') {
url = '{{ route('all.forex')}}';
}
$('#allServices').attr('action', url);
$('form#allServices').submit();
return true;
}
</script>
First Select Form, suppose redirect to the second form
<h3 class="card-title">PLACE AN ORDER</h3>
<p class="card-word">Select A Service Type Of Your Choice</p>
<form method="post" id="allServices" onsubmit="submitForm()">
@csrf
<div class="row">
<div class="col-lg-12">
<div class="mb-2">
<label class="form-label">Service Types</label>
<select class="form-control form-select mb-4" id="service" name="service">
<option>Select Service Type</option>
@foreach($services as $val)
<option value="{{ $val->id }}">{{ $val->service_categories }}</option>
@endforeach
</select>
</div>
</div>
</div>
<input class="btn waves-effect waves-light" type="submit" value="Order Now" style="background:teal; color: #fff;">
</form>
Second select form
<h3 class="card-title">PLACE AN ORDER</h3>
<p class="card-word">Select A Service Type Of Your Choice</p>
<form method="" action="" id="allServices">
@csrf
<div class="row">
<div class="col-lg-12">
<div class="mb-2">
<label class="form-label">Service Types</label>
<select class="form-control form-select mb-4" id="service" name="service">
<option>Select Service Type</option>
@foreach($academics as $aca)
<option value="{{ $aca->id }}">{{ $aca->academic_choice }}</option>
@endforeach
</div>
</div>
</div>
<input class="btn waves-effect waves-light" type="submit" value="Order Now" style="background:teal; color: #fff;">
</form>
My laravel route is for the service and academicchoice controller
Route::controller(ServiceController::class)->group(function() {
Route::get('/service/service/category','allservicecategory')->name('all.service.category');
});
Route::controller(Academic_Choice_Controller::class)->group(function() {
Route::get('/all/academics','allacademics')->name('all.academics');
});
i include the in the 2 pages with this to get them in the front end:
@php
$services = App\Models\ServiceCategory::all();
$academics = App\Models\Academic_choice::all();
$bkg = App\Models\Background::latest()->limit(1)->get();//all();
@endphp
Here is my database for service category and academic choice respectivelyenter image description here
Upvotes: -2
Views: 55