Solution 1 :

const toggleDisabled = (sel) => {
  const EL_target = document.querySelector(sel);
  EL_target.disabled = !EL_target.disabled;
};

const ELS_toggle = document.querySelectorAll("[data-toggle]");
ELS_toggle.forEach(el => el.addEventListener("change", function() {
  toggleDisabled(this.dataset.toggle);
}));
<input data-toggle="#input-1" type="checkbox">
<input id="input-1" name="price" value="">

Solution 2 :

Is this what you want?

<input id="price" class="form-control" name="price" disabled>
<input type ="checkbox" onchange = "document.querySelector('#price').disabled = !this.checked">

Problem :

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.

Comments

Comment posted by Professor Abronsius

how might a user

Comment posted by Roko C. Buljan

Makes more sense to use a checkbox, no?! (At least if we’re talking about only one set of elements ofc)

Comment posted by ArSeN

Are you aware you got an extra

Comment posted by user12137152

Have you tried any of the two methods?

By