Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function () {
- let typeChanged = false;
- $('.select2-class').select2({
- placeholder: 'Select option'
- });
- $('#category_select').on("change", function () {
- //getting the category id
- if (!typeChanged) {
- let selected_category_id = $("#category_select option:selected").val();
- $.ajaxSetup({
- headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}
- });
- $.ajax({
- url: "{{ url('/category/change') }}",
- method: 'post',
- data: {
- id: selected_category_id,
- },
- success: function (result) {
- $("#type_select").html('').select2({
- data: result.success
- });
- // console.log(result.success);
- }
- });
- }
- }); // end of on change category select
- $('#type_select').on("change", function () {
- typeChanged = true;
- let selected_type_id = $("#type_select option:selected").val();
- $.ajaxSetup({
- headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}
- });
- $.ajax({
- url: "{{ url('/type/change') }}",
- method: 'post',
- data: {
- id: selected_type_id,
- },
- success: function (result) {
- //retrieving category id that belongs to that type
- //and setting the category to the option
- $('#category_select').val(result.success);
- $('#category_select').select2().trigger('change');
- typeChanged = false;
- }
- });
- }); // end of on change category select
- }); //end of document ready function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement