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

306
Vistas
javascript alert not working mobile devices

I have some javascript alert code that displays an alert if a checkbox is not checked if a user tries to click on confirm button and it works fine on desktop but on mobile view/devices, it doesn't work and I tried adding touchstart, touch, touchend into the javascript next to click but nothing seems to work when testing it on my mobile, my code is below if anyone can help, please.

$(document).ready(function() {
  $('#confirmcheckout').on('click touchend', function() {
    if ($('#terms-condition').prop('checked') == true) {

    } else {
      alert("To proceed you must accept the terms.")
    }
  });
})

Thank you in advance

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I'm guessing that 'click touchend' could be firing twice on mobile.

This might help:

$(document).ready(function() {
  $('#confirmcheckout').on('click touchend', function(event) {
    event.stopPropagation();
    event.preventDefault();
    if ($('#terms-condition').prop('checked') == true) {

    } else {
      alert("To proceed you must accept the terms.")
    }
  });
})

EDIT: Another possible solution:

$(document).ready(function() {
  $('#confirmcheckout').on('touchend click', function(event) {
    if(event.type == 'touchend') {
        $(this).off('click');
    }
    if ($('#terms-condition').prop('checked') == true) {

    } else {
      alert("To proceed you must accept the terms.")
    }
  });
})

(if touchend works, remove click)

about 4 years ago · Juan Pablo Isaza Denunciar

0

Think I just solved it with the following code

<input id="terms-condition" type="checkbox" onclick="validate()" name="terms_condition" value="1" required="required" class="custom-control-input" {!! set_checkbox('terms_condition', '1') !!}>
<button class="checkout-btn btn btn-primary btn block btn-lg" onclick="validate()" data-attach-loading="disabled" data-checkout-control="confirm-checkout" data-request-form="#checkout-form" id="confirmcheckout">Confirm</button>

 function validate() {
if (document.getElementById('terms-condition').checked) {
alert("Thank you for agreeing to the terms");
} else {
alert("To proceed, you must accept the terms.");
}
}

It seems to work on both mobile and desktop view

about 4 years ago · Juan Pablo Isaza Denunciar
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