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

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

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 Report

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 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!