Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

92
Vistas
Toggle button both by click and by function

I got a problem switching a button both ways, by clicking on it and by changing it by a js-function which reacts on recieved mqtt messages and toggles the button. The first part works, the latter not. Here is my html

<label class="switch">
<input type="checkbox" value="On" id="onoff" onclick="onoff_dev();">
<span class="slider round"></span>
</label>

The js to toggle the button:

function onoff_dev() {
    currentvalue = document.getElementById('onoff').value;
    if (currentvalue == "Off") {
        document.getElementById("onoff").value = "On";
        switch("0");
    } else {
        document.getElementById("onoff").value = "Off";
        switch("1");
    }
}

And here the function, which is executed when a mqtt message arrives. The message is either 'r_message = On' or 'r_message = Off' It should change the slide button, but "document.getElementById('onoff').value = "On";" does not update the value of the button.

function onMessageArrived(r_message) {
    if (r_message == "On") {
        document.getElementById('onoff').value  = "On";
    }
    if (r_message == "Off") {
        document.getElementById('onoff').value  = "Off";
    }
}

Can you please help me? Thanks!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda