
<!-- /.card-header -->
<div class="card-body">
    <form id="validation2" action="{{route('admin::save_product_childcategory')}}" method="POST" enctype="multipart/form-data">
        @csrf


        <div class="row">
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label>Select Main Category</label>
                                <select name="maincatid" class="form-control" id="main_cat_idd">
                                    <option value="">Select...</option>
                                    @foreach($maincatlist as $cat)
                                        <option value="{{$cat->id}}">{{$cat->maincategory}}</option>
                                    @endforeach
                                </select>
                            </div>
                            @if ($errors->has('maincatid'))
                                <span class="alert alert-danger">{{ $errors->first('maincatid') }}</span>
                            @endif
                        </div>
                    </div>
                    <br>

                    <div class="row">
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label>Select Sub Category</label>
                                <select name="subcatid" class="form-control" id="subcat_idd">
                                    <option value="">Select...</option>
                                </select>
                            </div>
                            @if ($errors->has('subcatid'))
                                <span class="alert alert-danger">{{ $errors->first('subcatid') }}</span>
                            @endif
                        </div>
                    </div>



        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label>Child Category</label>
                    <input type="text" name="childcatname" class="form-control" placeholder="Enter ...">
                </div>
                @if ($errors->has('childcatname'))
                    <span class="alert alert-danger">{{ $errors->first('childcatname') }}</span>
                @endif


            </div>
        </div>
    
        
        

        <div class="row">

            <div class="col-md-12">
                <div class="form-group" style="text-align:center">
                    <input type="submit" value="Submit" class="btn btn-primary">
                </div>
            </div>
        </div>
    </form>
</div>

<!-- /.card-body -->
<script type="text/javascript">
    jQuery("#validation2").validationEngine({promptPosition: 'inline'});
    $('.select2').select2();
</script>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<!-- <script>
    $(document).ready(function() {
        $('#maincatid').change(function() {
            var maincatid = $(this).val();
            alert(maincatid);
           
        });
    });
</script> -->


<script>
    $(document).ready(function () {
        $('#main_cat_idd').change(function () {
            var mainCatId = $(this).val();
            if (mainCatId) {
                $.ajax({
                    type: "GET",
                    url: "{{ route('admin::get_subcategories') }}",
                    data: {main_cat_id: mainCatId},
                    success: function (res) {
                        if (res) {
                            $("#subcat_idd").empty();
                            $("#subcat_idd").append('<option value="">Select...</option>');
                            $.each(res, function (key, value) {
                                $("#subcat_idd").append('<option value="' + key + '">' + value + '</option>');
                            });
                        } else {
                            $("#subcat_idd").empty();
                        }
                    }
                });
            } else {
                $("#subcat_idd").empty();
            }
        });
    });
</script>







