0

I am trying to use masked input to make my date look like 9999-99-99 but doesen't seem to be effecting anything. I can't tell what I am doing wrong.

<script type="text/javascript" src="http://digitalbush.com/wp-content/uploads/2013/01/jquery.maskedinput-1.3.1.min_.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
jQuery(function ($) {
$("#date").mask("9999-99-99");
});
</script>

http://jsfiddle.net/doitlikejustin/xw2je/3/

This is my input box-

<input name="date" type="text" id="date" value="<?php echo $_SESSION['date'];?>" /> 
1
  • Are you using a correct link for the javascript file? Commented Aug 18, 2013 at 7:18

3 Answers 3

2

You need to include jQuery script first.

The order is important, since jQuery Masked input plugin depends on jQuery. You should tell the browser to load jQuery first and then only you can work on jQuery stuff.

For example (I tested this):

<html>

<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
    <script type="text/javascript" src="http://digitalbush.com/wp-content/uploads/2013/01/jquery.maskedinput-1.3.1.min_.js"></script>
    <script type="text/javascript">
    jQuery(function ($) {
    $("#date").mask("9999-99-99");
    });
    </script>
</head>

<body>
    <input name="date" type="text" id="date" value="" />
</body>
</html>

I hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Right, I thought I was? I used your code, did not seem to work. Could this be a problem? 'code' <input name="date" type="text" id="date" value="<?php echo $_SESSION['date'];?>" />
It shouldn't be a problem. May be you have some errors in the page. You can use Firebug on Firefox to see whether there are JavaScript errors
0

You just need to change jquery definition order, put version jquery file first and then put plugin jquery. It will solve your problem.

<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="http://digitalbush.com/wp-content/uploads/2013/01/jquery.maskedinput-1.3.1.min_.js"></script>

Comments

0

main jquery file should place first and then the addon.It will definitely solve ur problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.