Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm trying to get jQuery plug-in meioMask to work in a MVC Partial View.

As a trial, the following works:

<head>
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="jquery.meio.mask.min.js" charset="utf-8"></script>
<script type="text/javascript">
    jQuery(function($) {
        $('#StartTimeText').setMask('time');
});
</script>
</head>

<body>
<input type="text" id="StartTimeText" />
</body>

The text edit box gets a mask edit applied. However, my text edit box is in a MVC partial view that gets shown when user clicks on an item in the main view. In the main view's <head> I added the following:

<script src="@Url.Content("~/Scripts/jquery-1.8.3.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.meio.mask.min.js")" type="text/javascript"></script>

In CustomFormPartialView.cshtml, I have the following:

<script type="text/javascript">
    jQuery.ajax(
      function ($) {
        $('#StartTimeText').setMask('time');
      }
    );
</script>

<input type="text" id="StartTimeText" />

But the text box remains a regular text box with no edit mask applied. I assume this is because the setMask function isn't getting run. I've tried using jQuery.get and jQuery.post as well, none of them made any difference.

Sorry if this has already been asked, I've tried other solutions without any luck. I'm a bit new in this area, so if someone can post as complete code example as possible it'll be greatly appreciated. Thanks.

EDIT:

Following JasCav's suggestion, I've put the following in the <head> section of the file. As far as I can tell, the ajax function isn't getting run at all. This is using DevExpress's MVC Scheduler if that's any help. I'm not getting any errors in FireBug.

<script type="text/javascript">
  jQuery.ajax({
    url: '/WebTMS_MVC/Calendar/SchedulerPartial',
    type: 'POST',
    success: function (data, textStatus, xhr) {
      $('#StartTimeText').setMask('time');
    }
  });
</script> 
share|improve this question

You can use jQuery's ajax function provides a number of callbacks that you can use to perform specific actions after completion of the ajax call (success and complete are two). See more at jQuery's documentation for the ajax function.

$.ajax({
  url: yourUrl,
  type: "GET",
  data: formData,
  success: function(data) {
    // Do your stuff here.
});
share|improve this answer
    
Thanks, still not working unfortunately. I've edited my original question to post the changes I made. – Robo Dec 6 '12 at 21:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.