<div class="row">
    <div class="col-md-6 col-md-offset-3">
	    <div class="form-group {{ $errors->has('standard_id') ? ' has-error' : '' }}">
            <label class="control-label">Standard <span class="text-danger">*</span></label>
            {!! Form::select('standard_id',['' => '---- Select Standard ----'] +$dropdown ,null, ['class' => 'form-control js-example-basic-multiple','id'=>'standard_id','required'=>'required']) !!}
            <span class="help-block" id="error_category_id"><strong>{{ $errors->first('standard_id') }}</strong></span>
        </div>
		<div class="form-group {{ $errors->has('subject_id') ? ' has-error' : '' }}">
			<label class="control-label">Subject <span class="text-danger">*</span></label>
			<select class="form-control js-example-basic-multiple" name="subject_id" id="subject_id" required>
			    @if(!empty($record))
				@foreach($subject as $key=>$s)
				<option value="{{$key}}"
                    @if($record['subject_id']==$key)
                     <?php echo 'selected="selected"';?> 
                    @endif
                >{{$s}}</option>
				@endforeach
				@endif
			</select>
			<span class="help-block" id="error_subject_id"><strong>{{ $errors->first('subject_id') }}</strong></span>
		</div>
        <div class="form-group {{ $errors->has('name') ? ' has-error' : '' }}">
            <label class="control-label">Name <span class="text-danger">*</span></label>
            {!! Form::text('name',null, ['class' => 'form-control','required'=>'required']) !!}
            <span class="help-block" id="error_name"><strong>{{ $errors->first('name') }}</strong></span>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $('.js-example-basic-multiple').select2();
    });
</script>
<script type="text/javascript">
$("body").on("change", "#standard_id", function () {
		var row_id = $(this).val();
		
		$.ajax({
			type: "post",
			url: '{{ url('admin/getsubject') }}',
			data: {
				"_token": "{{ csrf_token() }}",
				"standard_id": row_id
			},
			error: function (result) {
			},
			success: function (result) {
				if(result.subjects==''){
					$('#subject_id option').remove();
				}else{
					$('#subject_id option').remove();
					$.each(result.subjects, function(key, value) {
						 $('#subject_id')
							  .append($('<option>', { value : key })
							  .text(value));
					});
				}
			}
		});
	});
</script>

