0
I am using Jquery to add mask to the Cpf field when the user is doing a search. However the mask is only enabled after making a Submit on the page (by clicking the search button).
<html>
<head>
<title> </title>
<script type="text/javascript" src="../style/scrpit.js"></script>
<script type="text/javascript" src="../style/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="../style/jquery.maskedinput.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#cpf").mask("999.999.999-99");
});
</script>
</head>
<body>
<div class="form-group col-md-5">
<input type="text" name="cpf" class="form-control" placeholder="CPF" id="cpf" required/>
</div>
<div class="form-group col-md-5">
<button type="submit" class="btn btn-primary btn-sm" value="Pesquisar" name="Pesquisar">Pesquisar</button>
</div>
</body>
</html>
Place
<script type="text/javascript" src="../style/scrpit.js"></script>
below the other scripts instead of before– Guilherme Nascimento
Your code is working here: https://jsfiddle.net/mrlew/vm3r7k43/ . There must be some other problem. What is the expected behavior? If your code comes from
scrpit.js
, and not the tag<script>
, As you put it, the problem may be the upload order, as mentioned by @Guilhermenascimento (but this would not work after form submission). In fact, it seems to be a clerical error there (typo):scrpit.js
is notscript.js
? Anyway, this one snippet presented in the question is working.– mrlew
@mrlew makes sense, I just said to move because if there was a script error it could be just for failure in the previous script, because if it was an answer I would have responded and not just commented on, summarizing is a tip ;)
– Guilherme Nascimento
@Guilhermenascimento yes, of course, so I also commented, to see if there is any further clarification, because I believe that elements are missing.
– mrlew
@mrlew I fully agree ;) and I say more, in such cases you can vote to close the question as
Não clara
orOff-topic > Erro de digitação
– Guilherme Nascimento
@mrlew really was another problem. At the end of the file I called Jquery (script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">). That was what was causing the problem. I ended up not inserting this code snippet in the question. Excuse me for the lack of attention and thanks for the help. As for the "scrpit" has also been corrected.
– Jeferson Leonardo