How Can I Include An Specific Form Based On The Selected Option Of
I have an with 3 options. these options come from the database. Every item in has an specific own form. I want that if i select option1, it shows form1 on the same page. so not switchting to other url I thought about using the @include in blade but the function runs instant if i open the page while i have made some if/else statements.
im not sure if i explain it perfectly but here is the code :
Selectbox:
<div class="form-group">
<select class="form-control col-lg-4" name="object" id="object">
<option value="" disabled selected>Maak een keuze</option>
@foreach($house_statuses as $status)
<option value="{{$status->house_status_description}}">
{{$status->house_status_description}}
</option>
@endforeach
</select>
</div>
My idea to include the form in Jquery/js
<script>
$(document).ready(function () {
$('#object').on('change', function () {
var optionValue = $(this).val();
// var optionText = $("#object option:selected").value;
$.ajax({
url: "/ajax/get/" + optionValue.toLowerCase() + "", success:
function (result) {
$('#col-10').text('@include('house.form.huur')')
}
});
});
});
</script>
The ajax call is for getting my variables that belong to the form
Hope someone has a suggestion what im doing wrong or what i can do better
Answer
The return
statement of the called controller method (/ajax/get/" + optionValue.toLowerCase()
) must be your form HTML.
Then in your AJAX success callback, correct $('#col-10').text('@include('house.form.huur')')
by $('#col-10').html(result)
. You may have to specify the dataType
as stated on the documentation.
Related Questions
- → OctoberCMS - How to make collapsible list default to active only on non-mobile
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → when i send data with ajax(jquery) i don't find the values in controller without form in laravel 5.1
- → DropzoneJS & Laravel - Output form validation errors
- → Knockout JS - How to return empty strings for observable fields
- → How to replace *( in a string
- → Get the calling element with vue.js
- → Sent Variable to Controller via Ajax in Blade
- → AJAX folder path issue
- → Onclick with argument causes javascript syntax error
- → KNockout JS - Automatic reload of ajax call