I have two select tag.
<div class = "form-group col-md-6 col-sm-6">
<label for="years">Name of Course*</label>
<select class="form-control input-sm required" id="courses_name" name="alumni_course">
<option value="">-- Select Any one --</option>
@foreach($coursename as $coursenames)
<option value="" ></option>
@endforeach
</select>
</div>
<div class = "form-group col-md-6 col-sm-6" id="dvPassport" style="display:none">
<label for="years">Name of Branch*</label>
<select class="form-control input-sm required" id="branch_name" name="alumni_branch">
@if(isset($branchname))
@foreach($branchname as $branchnames)
<option value="" ></option>
@endforeach
@endif
</select>
</div>
If from Name of Course option, any one select B.E./B.TECH. or DIPLOMA, then Name of Branch will be show and data will be related B.E./B.TECH. or DIPLOMA.
MY ajax in same page:
<script type="text/javascript">
$(document).ready(function() {
$("#courses_name").change(function() {
var courses_name1 = $("#courses_name").val();
var courses_name2 = courses_name1.split(",");
var id = courses_name2[0];
var courses_name2 = courses_name2[1];
if (courses_name2 == 'B.E./B.TECH.' || courses_name2 == 'DIPLOMA') {
$("#dvPassport").show();
$.ajax({
type: "GET",
url: "findbranch",
data: {
'id': id
},
}).done(function(data) {
$("#branch_name").html(data.html);
//console.log(data);
});
} else {
$("#dvPassport").hide();
}
});
});
</script>
Route is:
Route::get('findbranch','Auth\RegisterController@findbranch');
Controller is:
public function findbranch(Request $request)
{
$branchname = branchname::where('course_id', $request->id)->get();
$html = view('auth.register')->with(compact('branchname'))->render();
return response()->json(['success' => true, 'html' => $html]);
}
But data is not showing in Name of Branch.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire