I have a select option with many values, I need to toggle a field required or not based on the select option value, tried all possible solutions such as:
$(document).ready(function () {
});
function toggleFields(sel) {
var valuee = sel.value;
alert (valuee);
if (valuee < 7){
//$("#comment").setAttribute("required","");
alert("Removed");
$('#comment').required = false; //Correct
$('#comment').removeAttribute("required"); //Correct
}
else{
$('#comment').required = true; //Correct
$('#comment').setAttribute("required", "");
alert("Set");
}
}
a running example can be found into this fiddle