javascript - Laravel show undefined index:year even the field is hidden by jQuery
one text
Solution:
Change your jquery function to disable the form element while hiding it and enable the same while showing it.
<script>
$('#category').change(function(){
var responseID = $(this).val();
if(responseID =="student"){
$('#pDetails').removeClass("hidden");
$('#pDetails').addClass("show");
$( "#uyear" ).prop( "disabled", false );
} else{
$('#pDetails').removeClass("show");
$('#pDetails').addClass("hidden");
$( "#uyear" ).prop( "disabled", true );
}
console.log(responseID);
});
Instead of disabling the form element, you can give a default value like this.
<script>
$('#category').change(function(){
var responseID = $(this).val();
if(responseID =="student"){
$('#pDetails').removeClass("hidden");
$('#pDetails').addClass("show");
$('#uyear').val("");
} else{
$('#pDetails').removeClass("show");
$('#pDetails').addClass("hidden");
$('#uyear').val("faculty");
}
console.log(responseID);
});
Source