skip to Main Content

`i want to create a page that mark attendence of student in that page i just select any student name and in the other dropdowns its semester and batch and degree should auo selected

**
this is my code for blade view is there any error in the balde view **

                    @csrf
                    <select class="form-control mb-4" id="studentSelect">
                        <option value="">Select Student</option>
                        @foreach ($students as $student)
                            <option value="{{ $student->Student_id }}">{{ $student->Name }}</option>
                        @endforeach
                    </select>
                    <select name="batch_id"class="form-control mb-4" required>
                        <option value="" selected disabled>-- Select Batch --</option>
                        <option value="" id="batch"></option>
                    </select>
                    <select name="semester_id" class="form-control mb-4" required>
                        <option value="" selected disabled>-- Select Semester --</option>
                        <option value="" id="semester"></option>
                    </select>
                    <select name="degree_id" class="form-control mb-4" required>
                        <option value="" selected disabled>-- Select Degree --</option>
                        <option value="" id="degree"></option>
                    </select>
                </form>
                <script src="https://code.jquery.com/jquery-3.7.1.js" integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4="
                    crossorigin="anonymous"></script>
                <script>
                    $('#studentSelect').on('change', function() {
                        var studentId = $(this).val();
                        $.ajax({
                            type: 'POST',
                            url: '/getStudentDetails',
                            data: {
                                '_token': '{{ csrf_token() }}',
                                'Student_id': studentId
                            },
                            success: function(data) {
                                $('#semester').val(data.semester);
                                $('#batch').val(data.batch);
                                $('#degree').val(data.degree);
                            },
                            error: function(xhr, status, error) {
                                console.error(xhr.responseText);
                                // Handle the error appropriately, e.g., display an error message
                            }
                        });
                    });
                </script>

and this is the controller Code for attendece

<?php
namespace AppHttpControllers;
use AppModelsbatch;
use AppModelsdegrees;
use AppModelssemester;
use AppModelsstudents;
use IlluminateHttpRequest;
use IlluminateSupportFacadesDB;
use IlluminateSupportFacadesSession;
class attendanceController extends Controller
{
    function showAttendencePage() {
        if(Session::has('user')){
            $students = students::all();
            return view('Pages.facuilty.markAttendence',['students'=>$students]);
        }else{
            return view('index');
        }
    }
    public function getStudentDetails(Request $request)
{    $student = students::find($request->Student_id);
    if ($student) {
        return response()->json([
            'semester' => $student->Semester_id,
            'batch' => $student->Batch_id,
            'degree' => $student->Degree_id,
        ]);
    }
    return response()->json(['error' => 'Student not found']);
}
}

*

*and this is the web routes **

Route::group(['middleware' => ['web']], function () {
    Route::get('/mark/attendence/student',[attendanceController::class,'showAttendencePage'])->name('showAttendencePage');
    Route::post('/getStudentDetails', [attendanceController::class,'getStudentDetails'])->name('getStudentDetails');
});

so that is my code and tell me if any error is or any mistake that i can’t solve so please tell me

2

Answers


  1. $('#studentSelect').on('change', function() {
        var studentId = $(this).val();
        $.ajax({
            type: 'POST',
            url: '/getStudentDetails',
            data: {
                '_token': '{{ csrf_token() }}',
                'Student_id': studentId
            },
            success: function(data) {
                // Make Other ID's like this
                $('#semester').attr('selected','selected');// In this way we can select the dropdown option dynamically
                $('#semester').html(data.semester);// This line used to write the input value in the case there is not select options
    
                $('#batch').val(data.batch);
                $('#degree').val(data.degree);
            },
            error: function(xhr, status, error) {
                console.error(xhr.responseText);
                // Handle the error appropriately, e.g., display an error message
            }
        });
    });
    
    Login or Signup to reply.
  2.     $('#studentSelect').on('change', function() {
    
        var studentId = $(this).val();
    
        $.ajax({
            type: 'POST',
            url: '/getStudentDetails',
            data: {
                '_token': '{{ csrf_token() }}',
                'Student_id': studentId
            },
            success: function(data) {
                
                $('#semester').attr('selected','selected');
                $('#semester').html(data.semester);
    
                $('#batch').attr('selected','selected');
                $('#batch').html(data.batch);
    
                $('#degree').attr('selected','selected');
                $('#degree').html(data.degree);
    
         },
            error: function(xhr, status, error) {
    
                console.error(xhr.responseText);
                
            }
        });
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search