Blur event does not work on mobile

Asked

Viewed 68 times

0

I have an event Javascript Blur that doesn’t work on mobile phones. Works perfectly on desktops. Even on older browsers.

My code:

HTML

<label>CPF</label>
<input type="text" id="cpf" name="cpf" />
<div id="resultado"></div>

Javascript

$('#cpf').blur(function () {
    var chars = (this.value);
    $.post(URL + 'Ajax/buscaCpf', {val: chars}, function (busca) {
        $('#resultado').html(busca);
    });
    });

PHP/Ajax

$char = $_POST['val'];

$cpf_key = preg_replace('#[^0-9]#', null, $char);

$dados = connection::select("select * from tabela where cpf='".$char."'");
$reg = $dados - > fetchObject();

if (validador::validCPF($char)) {
    if (!empty($reg)) {
        $resultado = "<SCRIPT LANGUAGE='JavaScript' TYPE='text/javascript'>
      var resposta = confirm('Seu CPF já consta em nossa base de Dados. Deseja atualizar?');
              if (resposta == true) {
              window.location = '".URL."trabalhe/home/".$cpf_key."#cadastro';
                                        }
               else {
               window.location = '".URL."trabalhe/home';
                                        }

                                </SCRIPT>";
    } else {
        $resultado = '';
    }
} else {
    $resultado = "<SCRIPT LANGUAGE='JavaScript' TYPE='text/javascript'>
                                        alert('CPF inválido, favor verificar os dados digitados.');
                                        window.location = '".URL."trabalhe/home#cadastro';
                                   </SCRIPT>";
}
$retorno = $resultado;
                                        }

                                </SCRIPT>";
                    }
                    else {
                        $resultado = '';
                    }
                }
                else {
                    $resultado = "<SCRIPT LANGUAGE='JavaScript' TYPE='text/javascript'>
                                        alert('CPF inválido, favor verificar os dados digitados.');
                                        window.location = '" . URL . "trabalhe/home#cadastro';
                                   </SCRIPT>";
                }
                $retorno = $resultado;
  • "does not work on mobile phones" - no? android, Ios?

  • None, I tested on both.

  • Works well for me on IOS 10, iPhone 5 -> https://jsfiddle.net/wgchba2v/

  • :( tested in safari, google Chrome, uc browser. None displays the message.

  • My jsFiddle doesn’t work or your code?

  • It does work...

  • You can create a jsFiddle that plays back the problem you have so we can test?

  • Is it the confirm? I switched to Alert worked.

  • Please then answer your own question for search and resolution purposes!

  • Remove the Post??

  • No. Put the solution here.

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.