{{-- Extends layout --}}
@extends('layout.default')

{{-- Content --}}
@section('content')

<div class="card card-custom example example-compact">
    <div class="card-header">
        <h3 class="card-title">
            Assessment Marks
        </h3>
    </div>
    <!--begin::Form-->
    <form class="form" action="{{$action}}" method="POST">
        @csrf
        <!-- @isset($trial->Id)
        {{ method_field('PATCH')}}
        @endisset -->
        <div class="card-body">
            @if ($errors->any())
            <div class="alert alert-danger">
                <strong>Error!</strong>
                <ul>
                    @foreach ($errors->all() as $error)
                    <li></li>
                    @endforeach
                </ul>
            </div>
            @endif
            <div class="form-group row">
                <label class="col-lg-3 control-label">
                    Student:</label>
                <div class="col-lg-6 col-md-9 col-sm-12">
                    <select class="form-control kt-select2 select2" id="reg_id" name="reg_id" onchange="showsubject(this.value)">
                        <option value="">Select Student</option>
                        @foreach ($registrations as $row)
                        <option value="{{ $row ->id }}">{{ $row ->participant_name }}</option>
                        @endforeach
                    </select>
                </div>
            </div>

            <div class="form-group row">
                <label class="col-lg-3 control-label">
                    Subject:</label>
                <div id="txtHint" class="col-lg-6 col-md-9 col-sm-12">
                <select class="form-control kt-select2 select2" id="subject" name="subject">
                </select>
                </div>
            </div>
            <div class=" form-group row">
                <label class="col-lg-3 control-label">Total Marks</label>
                <div class="col-lg-6 col-md-9 col-sm-12">
                    <input type="text" class="form-control" id="totalmarks" name="totalmarks" maxlength="4" required />
                </div>
            </div>
            <div class="form-group row">
                <label class="col-lg-3 control-label">Marks scored</label>
                <div class="col-lg-6 col-md-9 col-sm-12">
                    <input type="text" class="form-control" id="marksscored" name="marksscored" maxlength="4" required />
                </div>
            </div>
        </div>
        <div class="card-footer">
            <div class="row">
                <div class="col-lg-9 ml-lg-auto">
                    <button type="submit" class="btn btn-success mr-2">Submit</button>
                    <button type="reset" class="btn btn-secondary">Cancel</button>
                </div>
            </div>
        </div>
    </form>
    <!--end::Form-->
</div>
@endsection
@section('scripts')
<script>
    $(document).ready(function() {
        $('.select2').select2();
    });
</script>
<script>
function showsubject(str)
{
    if (str == "") {
    document.getElementById("txtHint").innerHTML = "";
    return;
    } else {
    if (window.XMLHttpRequest)
    {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
    } else {
    // code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function()
    {
    if (this.readyState == 4 && this.status == 200) {
        // console.log(this.responseText);
        // document.getElementById("txtHint").innerHTML = this.responseText['msg'];
        var subject = $('#subject').empty();
        $.each(responseText.employees, function(i, employee){
            $('<option/>', {
                value:employee.id,
                text:employee.title
            }).appendTo(subject);
        })
    }
    };
    xmlhttp.open("GET","/getsubject/"+str,true);
    xmlhttp.send();
    }
}

</script>
@endsection
{{-- Scripts Section --}}
@section('scripts')

<script src="{{ asset('js/app.js') }}" type="text/javascript"></script>
@endsection