I want to submit the form when I select an option from select option but I don't want the page to reload after doing that.
I used the e.preventDefaut()
but the form stops saving to the database.
PS: it was saving perfectly before adding the preventDefault
but the page does reload.
Here is my code for the form:-
<form action="{{route('course.add')}}" method="POST" >
@csrf
<div class="aa">
<div class="dd">
<input type='checkbox' id='HiddenCheck{{$course->id}}' >
<input class='red' id = "b{{$course->id}}" onclick="showComboBox({{$course->id}})" >
<label class="class_name" value ="{{$course->id}}" >{{$course->courseNumber}}</label>
<input hidden type="number" value="{{$course->id}}" name ="course"/>
</div>
<div class="select-style" id="check{{$course->id}}" hidden >
<select name="a" id="season" >
<option value="" selected disabled hidden>Taken on </option>
<option value="Summer">Summer</option>
<option value="Fall">Fall</option>
<option value="Winter">Winter</option>
<option value="Spring">Spring</option>
</select>
</div>
</div>
</from>
and here is my Ajax code to submit the form:-
$('#season').on('change', function(e) {
e.preventDefault() ;
$(this).closest('form').submit();
});
I was expecting the form to be submitted and my data added to the database without reloading the page.
But when I added the preventDefaut()
the data stop saving in the database.