Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!