NotRocketScientist NotRocketScientist - 1 month ago 8
HTML Question

How do I disable and enable back the input type submit, once I have checked one input type radio?

I hope the title says everything.
I have a form, with lots of groups of input type radio, and I want the input type submit button to be disabled UNTIL one input type radio from each group has been checked. This example is just one group of input type radio, but it doesn't work obviously. What am I missing?

https://jsfiddle.net/Suiberu/70tkgk5t/

var current = $('input.class_x').filter(':checked');
var sbmtBtn = document.getElementById('SubmitButton');
sbmtBtn.disabled = true;

if (current.length > 0){
sbmtBtn.disabled = false;
}
else{
sbmtBtn.disabled = true;
}


thanks!

Answer

see updated fiddle

$(document).ready(function () {
var sbmtBtn = document.getElementById('SubmitButton');
sbmtBtn.disabled = true;
$('.class_x').click(function (){
if ($('.class_x').is(':checked')){//if only allow any on of the radio checked
sbmtBtn.disabled= false; 
}
else{
sbmtBtn.disabled = true;
}
})
});