web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Jquery mask function is undefined onchange event

(0) ShareShare
ReportReport
Posted on by

Hi,

I am trying to apply mask for the phone number field while changing the country field. In IE8 its working fine. But in chrome it showing exception like "Undefined" . Can anyone help me to fix this issue?

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi,

    Here is my code which invoked onchange event of country fieldfunction MaskPhoneNumber() {

       var MaskZip = "99999-9999";

       var LookupCountry = Xrm.Page.getAttribute("cpt_countryid").getValue();

       if (LookupCountry == null) {

           Mask("address1_postalcode", MaskZip);

       }

       else if (LookupCountry[0].name != "United States") {

           Mask("address1_postalcode", MaskZip);

       }

    }

    function Mask(field, format)

    {

       var oCtrl = Xrm.Page.getControl(field);

       if (oCtrl != null) {      

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

       }

    }

  • Community Member Profile Picture
    on at

    Hi,

    Please find the latest code below:

    function MaskPhoneNumber() {

       document.getElementById("telephone1").onclick = function () {

    var Maskphone = "(999) 999-9999 9999";

    var LookupCountry = Xrm.Page.getAttribute("cpt_countryid").getValue();

    if(LookupCountry != null)

    {

    var resultXml = XrmServiceToolkit.Soap.Retrieve("cpt_country", LookupCountry[0].id, ["cpt_phonemask"]);

    if (resultXml != null && resultXml.attributes['cpt_phonemask'] != null)

    {

    Maskphone =  resultXml.attributes['cpt_phonemask'].value;

    }

    }

    Mask("telephone1", Maskphone);

       };

    }

    function Mask(field, format)

    {

     //first check whether attribute exist or not

       var oCtrl = Xrm.Page.getControl(field);

       if (oCtrl != null) {

           oCtrl.setFocus(true);

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

       }

    }

  • Community Member Profile Picture
    on at

    Hi,

    Please find the below screenshot. On change of 'country' field, I need to apply mask for 'main phone' field.

    Format for masking is like <country code> <phone number> <extn>

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans