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

112
Views
jQuery -.on("click") Not Working on Mobile

I have a form that user can upload a file to the database. Unable to make .on("click") event on mobile device. It works fine on pc/laptop and the file is uploaded successful. On mobile, if I click the button, there is no response.

Codes

$(document).on("click", "#submit_upload", function(){
    var data = new FormData(document.querySelector("#fileInfo"));
    // If I comment below variables, 
    // it works fine on both mobile and computers.
    jab = data.get('jab'),
    kat_doc = data.get('jenis_fail'),
    doc_nama = data.get('nama'); 
    doc = data.get('file').size;

    $.ajax({
        url: url, 
        type: "POST",                   
        data: data,                     
        contentType: false,         
        cache: false,               
        processData:false,              
        success: function(data)         
        {
            $("#cont").html(data);

            if (!doc_nama) {
                $("#nama-doc").addClass("list-group-item list-group-item-warning");
            }

            if (jab == 0) {
                $("#jab").addClass("list-group-item list-group-item-warning");
            }

            if (kat_doc == 0) {
                $("#kat-doc").addClass("list-group-item list-group-item-warning");
            }

            if (!doc) {
                $("#doc").addClass("list-group-item list-group-item-warning");
            }

            $('#myModal').modal({backdrop: "static"});
            $('#myModal').on('shown.bs.modal', function () {
                $('#myInput').focus();
            });

        }
    });

});

Note: If I comment the variables jab/kat_doc/doc_nama/doc, it trigger the click event.

How do I want it to work with the variables?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Think mobile a second...
There is no mouse on a cell phone or tablet.

click is definitely a mouse event.

Try adding those events to you handler:
(Touch event reference)

$(document).on("click tap touchstart", "#submit_upload", function(){

This should do the trick.

over 4 years ago · Santiago Trujillo Report

0

change the first line of your function to below, and it should work:

     $(document).on('click touchstart', '#submit_upload', function(){

Or give a try to this,

     $(document).on('click touchstart tap', '#submit_upload', function(){
over 4 years ago · Santiago Trujillo Report

0

try this:

$('#submit_upload').on('click', function(){...});
over 4 years ago · Santiago Trujillo 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!