Problem with mask in form

Asked

Viewed 139 times

3

I’m using the plugin Masked Input Digitalbrush to format my phone field in the form, I tried this way and it didn’t work, someone can help me?

<head>  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js">     </script>
        <script type="text/javascript" src="assets/mascara.js"></script>
</head>

And in the <body>:

<script type="text/javascript">
    jQuery(function($){
    $("#fone").mask("(99) 9999-9999");
    });
</script>

<div class="col-lg-6 col-sm-6 ">
<form id="form" method="post" action="mail/phpmailer.php">
    <input type="text" class="form-control" placeholder="Nome completo:" name="nome">
    <input type="text" class="form-control" placeholder="E-mail:" name="email">
    <input type="text" class="form-control" placeholder="Número para contato:" name="fone" id="fone">
    <textarea rows="6" class="form-control" placeholder="Digite sua mensagem" name="msg"></textarea>
    <button class="btn btn-success" id="enviar">Enviar</button>
</form>
</div>

1 answer

2

Use the Zero instead

$("#fone").mask("(00) 0000-0000");

Or put jquery in the head and then you can use jquery

$(document).ready(function() {
   $("#fone").mask("(99) 9999-9999");
}
  • I did the script in head and it didn’t work, placeholder could influence this script?

  • You have to put jquery.js before this code. jquery.js goes to Head. It can be in BODY

  • No head: <script src="assets/mascara.js"></script>&#xA; <script type="text/javascript">&#xA; $(document).ready(function($){&#xA; $("#fone").mask("(99) 9999-9999");&#xA; });&#xA; </script> No body: <script type="text/javascript">&#xA; jQuery(function($){&#xA; $("#fone").mask("(99) 9999-9999");&#xA; });&#xA;</script>

  • And there’s jquery.js before the mascara.js?

  • This: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> ?

  • Yeah. That’s the one.

  • I edited the question, you know where I’m wrong?

  • I used a tutorial and got it, thanks for the help! http://codigofonte.uol.com.br/codigos/mascara-para-phones-de-8-e-9-digitos-jquery

  • Turned out to be what?

  • I followed that tutorial and put the script inside the tag form, then in the phone’s Hover applied the mask

Show 5 more comments

Browser other questions tagged

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