How to import external Javascript and put masks on inputs?

Asked

Viewed 291 times

0

Hello, all right?

I saw some tutorials on the internet to put masks input in HTML, and as I am new in Javascript I imported the external library as shown below, but I must have imported wrong or used the function incorrectly, because the mask is not being applied.

Follows the code:

<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.maskedinput.js" type="text/javascript"></script>
<script type="text/javascript">
    [...]

    jQuery(function($){
        $("#inputTelefone").mask("(99) 9999-9999");
    });
</script>

[...]

<input type="text" name="contato" id="inputTelefone" class="form-control">

Note: I am using the plugin Masked Input Plugin for jQuery, whose readme is available at https://github.com/digitalBush/jquery.maskedinput/blob/master/README.md

I downloaded the file jquery.maskedinput.js from the plugin page, put in the same folder as the HTML file and worked.

  • jquery.js and jquery.maskedinput.js files are in the same folder as the html file?

  • No... I will try to download the files and put them in the same folder. So I come here to tell you if it worked. Thank you, Wictor!

  • On the Chrome or firefox console shows an error?

  • As you have already edited in the question, the problem was in the location of your file. I recommend reading the following question to contextualize yourself with paths: https://answall.com

1 answer

-3

 <script>
   $(document).ready(function () {
       $("#inputTelefone").mask("(99) 9999-9999");
    });
 </script>

Try to use it this way

Browser other questions tagged

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