locked
Having problems capitalising text using javascript, script not working - code inside. RRS feed

  • Question

  • I've got a problem with a little a capitalisation script that is supposedly good that I copied from another source, the problem is I can't get it to work. I'm sure I am missing something vital here. Any suggestions would be greatly appreciated. 

    ----

    String.prototype.capitalize = function() {
        return this.charAt(0).toUpperCase() + this.slice(1);
    };

    function capitalName() {
        var fullName = Xrm.Page.getAttribute("fullname").getValue();
        fullName.capitalize();
        Xrm.Page.getAttribute("fullname").setValue(fullName);
    }





    • Edited by Sebd.DD Monday, November 11, 2013 8:56 AM
    Monday, November 11, 2013 8:55 AM

Answers

  • Hi Matt,

    I assumed you are referring to the Full Name for a Contact. If so, try something like this (*tested):

    String.prototype.capitalize = function() {
        return this.charAt(0).toUpperCase() + this.slice(1);
    };
    
    function capitalName() {
        var firstName = Xrm.Page.getAttribute("firstname").getValue();
        var lastName = Xrm.Page.getAttribute("lastname").getValue();
        Xrm.Page.getAttribute("firstname").setValue( firstName.capitalize() );
        Xrm.Page.getAttribute("lastname").setValue( lastName.capitalize() );
    }


    Eric UNG [Senior Analyst Programmer :: Sydney, Australia]

    • Marked as answer by Sebd.DD Monday, November 11, 2013 10:32 AM
    Monday, November 11, 2013 10:15 AM

All replies

  • Hi Matt,

    I assumed you are referring to the Full Name for a Contact. If so, try something like this (*tested):

    String.prototype.capitalize = function() {
        return this.charAt(0).toUpperCase() + this.slice(1);
    };
    
    function capitalName() {
        var firstName = Xrm.Page.getAttribute("firstname").getValue();
        var lastName = Xrm.Page.getAttribute("lastname").getValue();
        Xrm.Page.getAttribute("firstname").setValue( firstName.capitalize() );
        Xrm.Page.getAttribute("lastname").setValue( lastName.capitalize() );
    }


    Eric UNG [Senior Analyst Programmer :: Sydney, Australia]

    • Marked as answer by Sebd.DD Monday, November 11, 2013 10:32 AM
    Monday, November 11, 2013 10:15 AM
  • Thank you so much. It worked perfectly.
    Monday, November 11, 2013 10:33 AM