dimanche 14 juillet 2019

How to get selected Data value to the route?

Hello everyone I'm new to Stack overflow and posting for first time. I' m making an attendance management system for School. In my registration and attendance table I have

Registration : class_id, section_id, user_id.

Attendance :  date, user_id, remarks.

I want the user to select the Class then Section and Date and then it shows the all Users of that class and Section through registration table.

I'm having problem in taking that selected data to the route. I have tried this I want the data from dropdowns to in this form

<a href="">

PHP PAGE

@php use Illuminate\Support\Facades\DB;
$classs = DB::table("classses")->pluck("title","id");
$registrations= DB::table("registrations")->pluck("class_id","section_id");


@endphp



        <div class="form-group row">

            <label for="title" class="col-md-4 col-form-label">Select Class:*</label>

            <div class="col-md-4 col-form-label">
                <select name="class_id" class="form-control" style="width:360px" id="class_id" required autofocus>
                    <option value="">--- Select Class ---</option>
                    @foreach ($classs as $key => $value)
                        <option  value=""></option>
                    @endforeach
                </select>

            </div>
        </div>
        <div class="form-group row">
            <label for="title" class="col-md-4 col-form-label">Select Section:*</label>
            <div class="col-md-4 col-form-label">
                <select name="section_id" class="form-control" style="width:360px" required autofocus>
                    <option value="">--- Select Section --- </option >
                </select>
            </div>

        </div>



        <a href="">

            <div class="form-group " align="right">

            <button type="submit" class="btn btn-primary">

                
            </button>

        </div>
        </a>

        <script type="text/javascript">
            $(document).ready(function() {
                $('select[name="class_id"]').on('change', function() {
                    var classID = $(this).val();
                    if(classID) {
                        $.ajax({
                            url: '/myform/ajax/'+classID,
                            type: "GET",
                            dataType: "json",
                            success:function(data) {


                                $('select[name="section_id"]').empty();
                                $.each(data, function(key, value) {
                                    $('select[name="section_id"]').append('<option value="'+ key +'">'+ value +'</option>');
                                });

                            }
                        });
                    }else{
                        $('select[name="section_id"]').append('<option >No Section Found</option>');
                    }
                });
            });
        </script>


    </div>
</div>
</div>

Mainly having issues to get id of selected data from drop downs trying this:

   <a href="">

            <div class="form-group " align="right">

            <button type="submit" class="btn btn-primary">

                
            </button>

        </div>
        </a>

want to transfer id in this form in routes

 Route::any('/registration/data/{class_id}/{section_id}','AttendanceController@getUsers');



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire