Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

109
Visualizações
Toggle a boolean with two buttons

There are 3 booleans: a, b and c.

a and b are like buttons. They are normaly false. Only when triggered are true. Like an impulse.

When I triiger the a, the c should be true and should keep the sate untill the b is triggered. After triggering b, the c should go into false, keeping the state untill the a is triggered again.

I want to write it in JavaScript. I need it for hmi software to control the real buttons. Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use ternary operators (?:) and negation (!):

let A = false, B = false, C = false, a = document.getElementById('a'), b = document.getElementById('b'), c = document.getElementById('c');

function changeC(clickedBtn) {
  if(clickedBtn === 'a') {
    a.innerHTML = A === false ? true : false;
    A = !A;
  }
  else if(clickedBtn === 'b') {
    b.innerHTML = B === false ? true : false;
    B = !B;
  }
  c.innerHTML = C === false ? true : false;
  C = !C;
}
<button id="a" onclick="changeC('a')"> false </button>
<button id="b" onclick="changeC('b')"> false </button>

<button id="c"> false </button>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda