Why will this Javascript run on individual page but not from a common file?

67 views Asked by At

I've got an ASP.NET MVC app and I'm trying to use this Masked Input Plugin to mask/hint at dates. If I put this script in the @section Scripts{} at the bottom of the page, it functions just fine.

<script type="text/javascript">
    $(document).ready(
        function() {
            $(function($) {
                $(".datemask").mask("99/99/9999", { placeholder: "mm/dd/yyyy" });
            });
        });
</script>

But if I try to put it in a separate script file in the Scripts folder, so it runs on all pages, it never seems to run. I have another script running from the Scripts folder to add the jQuery date picker to my date fields:

$(document).ready(function() {
    $(":input[type='datetime']").each(function() {
        $(this).datepicker();
    });

This script runs just fine on every page (it's loaded from the _Layout.cshtml partial view). But when I put my masking script in that file, whether part of the existing .each function, part of the existing .ready function, or in it's own .ready section, it never masks the textbox.

Is this something quirky about the Masked Input Plugin, or am I missing something about using JavaScript in MVC?

0

There are 0 answers