locked
JQuery Mask in not working in On onload of the form RRS feed

  • Question

  • Hi,

    I am trying to mask the fax,telephone attributes in ms crm using 

    $("#fax").mask("999-999-9999");
    $("#telephone1").mask("999-999-9999");

    Both the fields are visible on the fourm...but i am facing the following error

    when i debuged ,i am getting error at mask,as mentioned above

    

    Please help....:)

    Thursday, July 11, 2013 9:07 AM

Answers

  • Hi,

    I suggest you use the IE F12 Script debugger to step through your code to find where the undefined error is coming from. Put a 'debugger' statement in your javascript just before the issue.

    I suspect it'll be that the jQuery alias $ is not defined or the mask plugin is not defined. 

    You might want to check that you are not running into async loading issues where the plugin is loading before jQuery - try putting the mask plugin in the same webresource as jQuery.

    hth


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marked as answer by Deepthi_1988 Saturday, July 13, 2013 9:16 AM
    Thursday, July 11, 2013 3:14 PM
    Answerer
  • Hi,

    It is caused by async js loading. So we need to make the jquery loading before the jquery_mark.

    Here is some sample code

    function loadScript(url)  

    {  

        var x ;  

     if ( window.XMLHttpRequest ) // Gecko

            x=new XMLHttpRequest() ;

        else if ( window.ActiveXObject ) // IE

            x=new ActiveXObject("MsXml2.XmlHttp") ;

        x.open('GET', url, false); 

        x.send(null);  

        eval(x.responseText);  

        var s = x.responseText.split(/\n/);  

        var r = /^(?:function|var)\s*([a-zA-Z_0-9]+)/i; 

        for (var i = 0; i < s.length; i++)  

        {  

            var m = r.exec(s[i]);  

            if (m != null)  

                window[m[1]] = eval(m[1]);  

        }  

    function onload()

    {

    loadScript("/WebResources/new_jquery");

    loadScript("/WebResources/new_jquery_mask");

    Mask("mobilephone", "9999 9999");

    }

    function Mask(field, format)

    {

      $("#"+field).mask(format);

    }

    Wilson

    • Marked as answer by Deepthi_1988 Friday, October 18, 2013 5:16 AM
    Monday, July 15, 2013 8:02 AM

All replies

  • Hi,

    Are you sure that you have jQuery and the JQuery mask plugin loaded as a webresource on your form?

    hth


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Thursday, July 11, 2013 10:14 AM
    Answerer
  • yes it is loaded in the form,version is 1.3
    Thursday, July 11, 2013 10:43 AM
  • Hi,

    I suggest you use the IE F12 Script debugger to step through your code to find where the undefined error is coming from. Put a 'debugger' statement in your javascript just before the issue.

    I suspect it'll be that the jQuery alias $ is not defined or the mask plugin is not defined. 

    You might want to check that you are not running into async loading issues where the plugin is loading before jQuery - try putting the mask plugin in the same webresource as jQuery.

    hth


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marked as answer by Deepthi_1988 Saturday, July 13, 2013 9:16 AM
    Thursday, July 11, 2013 3:14 PM
    Answerer
  • Hi,

    It is caused by async js loading. So we need to make the jquery loading before the jquery_mark.

    Here is some sample code

    function loadScript(url)  

    {  

        var x ;  

     if ( window.XMLHttpRequest ) // Gecko

            x=new XMLHttpRequest() ;

        else if ( window.ActiveXObject ) // IE

            x=new ActiveXObject("MsXml2.XmlHttp") ;

        x.open('GET', url, false); 

        x.send(null);  

        eval(x.responseText);  

        var s = x.responseText.split(/\n/);  

        var r = /^(?:function|var)\s*([a-zA-Z_0-9]+)/i; 

        for (var i = 0; i < s.length; i++)  

        {  

            var m = r.exec(s[i]);  

            if (m != null)  

                window[m[1]] = eval(m[1]);  

        }  

    function onload()

    {

    loadScript("/WebResources/new_jquery");

    loadScript("/WebResources/new_jquery_mask");

    Mask("mobilephone", "9999 9999");

    }

    function Mask(field, format)

    {

      $("#"+field).mask(format);

    }

    Wilson

    • Marked as answer by Deepthi_1988 Friday, October 18, 2013 5:16 AM
    Monday, July 15, 2013 8:02 AM