Please tell me if the input disabled , it is set to chek. How to make that check was not installed if input disabled ?

 function check(number) { document.getElementById('stol['+number+']').checked = true; } 
 <input type="radio" class="stoli" name="stol" id="stol[1]" > <input type="radio" class="stoli" name="stol" id="stol[2]" disabled><br> <a onclick="check(2)">Check</a> 

  • one
    The disabled attribute is intended for users . It does not affect the effect of JS scripts. - hindmost
  • Alternatively, check for disabled . If the element is disabled , then do not set checked = true - Bogdan

2 answers 2

A condition is added - if the specified element is inactive (disabled) - we turn around and don’t see what’s next (return). Otherwise, we execute the code.

 function check(number) { if( document.getElementById('stol['+number+']').disabled ) {return;} else {document.getElementById('stol['+number+']').checked = true;} } 

    By checking for disabled:

     function check(number) { let input = document.getElementById('stol['+number+']'); if(!input.hasAttribute('disabled')) { input.checked = true; } } 
     <input type="radio" class="stoli" name="stol" id="stol[1]" > <input type="radio" class="stoli" name="stol" id="stol[2]" disabled><br> <a onclick="check(2)">Check</a>