Javascript using mobile browser does not run [closed]

0

I have a javascript that does formatting form fields, it works well the most on mobile does not work.

Thanks for the help

<script>

      function formatar(mascara, documento) {
        var i = documento.value.length;
        var saida = mascara.substring(0, 1);
        var texto = mascara.substring(i)

        if (texto.substring(0, 1) != saida) {
            documento.value += texto.substring(0, 1);
        }
    }

</script>



        <div class="row">

            <div class="col-sm-7 col-md-7">
                <div class="form-group col-md-3">
                    <label for="cpf">CPF:</label>
                    <input type="text" maxlength="14" OnKeyPress="formatar('###.###.###-##', this)" class="form-control" id="cpf" placeholder="Digite um valor...">
                </div>
            </div>
        </div>
    
asked by anonymous 02.05.2017 / 16:42

1 answer

1

I took a quick look here and saw that in this case it would be best to use onkeydown events or onkeyup instead of onkeypress , according to reports obtained from the following links: keypress not raised , keypress not firing . There is some incompatibility with some specific versions of the android and the browser.

    
02.05.2017 / 16:59