How to disable input buttons in seperate modes?

I have to code a calculator in JS and i want for exampe if i press the radio button “Binär” that i can only press the 0, 1 ; if i press “Dezimal” i cann press 0-9, but not A-F.

function onclickRadio(umrechnung)                               
> {
let displayZahl = Number(document.getElementById("textboxDisplay").value);

if(umrechnung == "Binär")
>   {
displayZahl = DezimalzahlZuBinaer(displayZahl);
modus = "Binär"
>   }

document.getElementById("textboxDisplay").value = displayZahl;

if(umrechnung == "hexa")
>   {
displayZahl = DezimalzahlZuHexa(displayZahl);
modus = "Hexa"
>   }

document.getElementById("textboxDisplay").value = displayZahl;

if(umrechnung == "dezimal")

displayZahl = BinaerZuDezimal(document.getElementById("textboxDisplay").value); 
modus = "dezimal"
>   }

document.getElementById("textboxDisplay").value = displayZahl;
> }
> </script>
> </head>

> <body>
>   <label> <input type = "radio" name = "Umrechnung" value = "hexa" onclick="onclickRadio('hexa')" /> Hexadezimal </label>
>   <label> <input type = "radio" name = "Umrechnung" value = "Binär" onclick="onclickRadio('Binär')" /> Binär </label>
>   <label> <input type = "radio" name = "Umrechnung" value = " Dezimal" onclick="onclickRadio('dezimal')" checked /> Dezimal  </label>
>   <input id="textboxDisplay" readonly />
>   <input type="button" value="1" onclick="AddLetter('1')" />
>   <input type="button" value="2" onclick="AddLetter('2')" />
>   <input type="button" value="3" onclick="AddLetter('3')" />
>   <input type="button" value="4" onclick="AddLetter('4')" />
>   <input type="button" value="5" onclick="AddLetter('5')" />
>   <input type="button" value="6" onclick="AddLetter('6')" />
>   <input type="button" value="7" onclick="AddLetter('7')" />
>   <input type="button" value="8" onclick="AddLetter('8')" />
>   <input type="button" value="9" onclick="AddLetter('9')" />
>   <input type="button" value="0" onclick="AddLetter('0')" />
>   <input type="button" value="A" onclick="AddLetter('A')" />
>   <input type="button" value="B" onclick="AddLetter('B')" />
>   <input type="button" value="C" onclick="AddLetter('C')" />
>   <input type="button" value="D" onclick="AddLetter('D')" />
>   <input type="button" value="E" onclick="AddLetter('E')" />
>   <input type="button" value="F" onclick="AddLetter('F')" />
>   <input type="button" value="+" onclick="Plus()" />
>   <input type="button" value="-" onclick="Minus()" />
>   <input type="button" value="*" onclick="Mal()" />
>   <input type="button" value="/" onclick="Geteilt()" />
>   <input type="button" value="Mod" onclick="Restwert()" />
>   <input type="button" value="Löschen" onclick="Weg()" />
>   <input type="button" value="=" onclick="Gleich()" />
> </body>

i tried <button disabled> , but than its permanent disbaled. i just want to disable it when i am in the different mode.

To enable the buttons belonging to the selected base and disable all the other ones, you need a strategy that will be triggered when the click event occurs on those radio button options (binary/decimal/hex).

In particular regarding to that aspect, I used the classes digit base2 base10 base16 on those buttons so that by using basic css selectors I could, each time, first disable all of them, and then enable only those belonging to the selected base 2, 10, 16.

//disable all the .digit elements
document.querySelectorAll('.digit')
  .forEach(el => el.disabled = true);
                      
//enable all the .digit elements having the selected base    
document.querySelectorAll(`.digit.base${selectedBase}`)
  .forEach(el => el.disabled = false); 

But in general I had to rewrite your logic in the slimmest way possible mainly addressing the followings:

  • adding event handlers using addEventListener instead of inline event
    handlers because it’s not
    reccomended
    to mix javascript code with html.
  • Using css classes digit base16 base10 base2 to declare to which
    base belonged each digit button.. so to have a convenient way to
    discern which one to enable/disable according to the selected base;
  • Using
    parseInt
    to parse a string returning the corresponding number according to the
    radix (base);
  • Using
    Number.toString
    to convert a number to string according to the radix (base);
const number = document.getElementById("number");

//selects all the .digit elements
document.querySelectorAll('.digit')
  //for each one of them (as el)
  .forEach( el => {
    //adds the click event handler
    el.addEventListener('click', (event)=>{
      const digit = event.target.value;
      if(number.value == '0')
        number.value = '';      
      number.value += digit;
    })
  });

//selects all the input[name="mode"]
document.querySelectorAll('input[name="mode"]')
  //for each one of them (as el)
  .forEach( el => {
    //adds the click event handler
    el.addEventListener('click', (event)=>{
    
      //the base selected from the radio button triggering the event
      const selectedBase = event.target.value;
      
      //disable all the .digit elements
      document.querySelectorAll('.digit').forEach(el => el.disabled = true);
      
      //enable all the .digit elements having the selected base
      document.querySelectorAll(`.digit.base${selectedBase}`).forEach(el => el.disabled = false);  
      
      //parse the number in the input box using its stated base
      const currentNumber = parseInt(number.value, number.dataset.base);
      //rewrite the number in the input box using the selected base
      number.value = currentNumber.toString(selectedBase).toUpperCase();
      
      //save the selected base in the data-base attribute
      number.dataset.base = selectedBase;      
    })
  });
input[type="radio"],
input[type="button"]
{
  cursor: pointer;
}
<label>Hexadecimal</label>
<input type="radio" name="mode" value="16">
<br>
<label>Binary</label>
<input type="radio" name="mode" value="2">
<br>
<label>Decimal</label>
<input type="radio" name="mode" value="10" checked>

<br>
<br>

<input id="number" data-base="10" value="0" readonly>

<input type="button" value="0" class="digit base16 base10 base2">
<input type="button" value="1" class="digit base16 base10 base2">
<input type="button" value="2" class="digit base16 base10">
<input type="button" value="3" class="digit base16 base10">
<input type="button" value="4" class="digit base16 base10">
<input type="button" value="5" class="digit base16 base10">
<input type="button" value="6" class="digit base16 base10">
<input type="button" value="7" class="digit base16 base10">
<input type="button" value="8" class="digit base16 base10">
<input type="button" value="9" class="digit base16 base10">
<input type="button" value="A" class="digit base16">
<input type="button" value="B" class="digit base16">
<input type="button" value="C" class="digit base16">
<input type="button" value="D" class="digit base16">
<input type="button" value="E" class="digit base16">
<input type="button" value="F" class="digit base16">

<br>
<br>

<input type="button" value="+" onclick="Plus()" disabled>
<input type="button" value="-" onclick="Minus()" disabled>
<input type="button" value="*" onclick="Mal()" disabled>
<input type="button" value="/" onclick="Geteilt()" disabled>
<input type="button" value="Mod" onclick="Restwert()" disabled>
<input type="button" value="Löschen" onclick="Weg()" disabled>
<input type="button" value="=" onclick="Gleich()" disabled>

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật