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

196
Visualizações
check toggle button only when conditions met else it should remain unchecked

I created a toggle button using checkbox and tried to apply the logic below:

1] If user clicks on toggle switch id="accountability", one modal will appear and ask for some user input and when user enter those details then only that toggle will get checked

2] If User doesn't provide input then toggle should remain unchecked

3] if toggle is already checked and user click on it, it must unchecked.

But the problem is toggle button is getting checked whenever I click on it and then the modal come. one solution is to uncheck every time whenever point 2 is not fulfilled

Is there any other way to do that.

HTML

<div class="toggle">
    <label class="switch">
        <input type="checkbox" id="accountability">
        <span class="slider round"></span>
    </label>
</div>

Js

chrome.storage.local.get("isAccountabilityPatner", function (val) {
  if (val.isAccountabilityPatner) $("#accountability").prop('checked', true);
});

$("#accountability").on("change", function () {
  let ischk1 = $(this).is(":checked");
  if(ischk1){
    $(".accountabilty_popup").show();
  } else {
    chrome.storage.local.set({ "isAccountabilityPatner" : false });
  }
});

$("#accountabilitySubmit").click(() => {
  $("#accountability").prop('checked', false);
  let email1 = $("#accountabilityMail").val();
  let email2 = $("#accountabilityChkMail").val();
  let regex = new RegExp('[a-z0-9]+@[a-z]+\.[a-z]{2,3}');
  if(!regex.test(email1) || !regex.test(email2)){
    alert("Enter valid Eamil address");
  }
  else if(email1 != email2){
    alert("Both Email should be same");
  }
  else{
    chrome.storage.local.set({ "isAccountabilityPatner" : true });
  }
});
about 4 years ago · Juan Pablo Isaza
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