Is this what you want?
<input id="price" class="form-control" name="price" disabled>
<input type ="checkbox" onchange = "document.querySelector('#price').disabled = !this.checked">
I would like to enable an input when the radio is checked and then disable it when he’s unchecked.
HTML
<input id="nam" class="col-md-4 form-check-input" type="radio" name="nam" checked="" data-waschecked="true" onclick="check()"> <
<input id="price" class="form-control" name="price" value="" disabled="disabled">
JS
$(function(){
$('input[name="nam"]').click(function(){
var $radio = $(this);
if ($radio.data('waschecked') == true)
{
$radio.prop('checked', false);
$radio.data('waschecked', false);
}
else
$radio.data('waschecked', true);
$radio.siblings('input[type="radio"]').data('waschecked', false);
});
});
function check() {
var check = document.getElementById('nam').checked;
if (check === true){
document.getElementById('price').removeAttr('disabled');
}
else if (check === false){
document.getElementById('price').attr('disabled','disabled');
}
}
Any ideas?
Thank in advance.
Makes more sense to use a checkbox, no?! (At least if we’re talking about only one set of elements ofc)