locked
jScript: Force Title Case in name fields? RRS feed

  • Question

  • Hello there,

    I have a requirement in which I must default the case of a text field to Title Case using jScript.

    For example, if someone writes john doe, it the script should format the text to John Doe.

    Any ideas how to do that?

    Regards,
    P.

    PS: I don't agree with it, but it is a request nonetheless :)

    • Edited by pmdci Monday, March 12, 2012 1:49 PM better explanation of requiremt
    Monday, March 12, 2012 1:27 PM

Answers

  • Hi Jason ,

     you can write a Javascipt function to do this Either onLoad , or OnSave depending on your exact requirement

    var str = "hello world"; 
    str = str.toLowerCase().replace(/\b[a-z]/g, function(letter) { 
        return letter.toUpperCase(); 
    }); 
    alert(str); //Displays "Hello World" 
    

    hth
    dkay

     if the response answered your question, please take a minute and mark the response as an answer.

    • Proposed as answer by D kay Monday, March 12, 2012 2:40 PM
    • Marked as answer by pmdci Wednesday, April 4, 2012 10:08 AM
    Monday, March 12, 2012 2:40 PM

All replies

  • If I understood right, you need to default a field to a specific value...

    function OnLoad() {
        if (Xrm.Page.ui.getFormType() == 1) {
            Xrm.Page.getAttribute("title").setValue("Title Case");
        }
    }
    
    This will fire only on a new record. Add this to the form's OnLoad event. 

    Jason Lattimer

    Monday, March 12, 2012 1:45 PM
    Moderator
  • Hi Jason,

    Thanks but that is not it.

    What I need is that if someone types jason lattimer, it will format it to Jason Latimer.

    Regards,
    P.


    MCC, MCP, MCTS
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".

    Monday, March 12, 2012 1:48 PM
  • Hi Jason ,

     you can write a Javascipt function to do this Either onLoad , or OnSave depending on your exact requirement

    var str = "hello world"; 
    str = str.toLowerCase().replace(/\b[a-z]/g, function(letter) { 
        return letter.toUpperCase(); 
    }); 
    alert(str); //Displays "Hello World" 
    

    hth
    dkay

     if the response answered your question, please take a minute and mark the response as an answer.

    • Proposed as answer by D kay Monday, March 12, 2012 2:40 PM
    • Marked as answer by pmdci Wednesday, April 4, 2012 10:08 AM
    Monday, March 12, 2012 2:40 PM
  • Hi

    Did this help?

    Please make sure to mark as answer to the response that helped you get through. This will help others with similar problem identify the answer and also close this thread as resolved.

    Thanks

    Dkay

    Monday, March 12, 2012 8:49 PM
  • I will try it tomorrow and let you know :)

    Cheers,
    P.

    UPDATE (04-APR-2012): Sorry for the delay in returning to you. It does work! Thanks a lot for your help. I even tried with some CaMel cASe tExT and it works perfectly. 


    • Edited by pmdci Tuesday, April 10, 2012 11:38 AM typo
    Monday, March 12, 2012 10:06 PM