Javascript using mobile browser does not run

Asked

Viewed 356 times

0

I have a javascript that makes formatting form fields, it works much more on mobile does not work.

I appreciate 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>

1 answer

1


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

Browser other questions tagged

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