javascriptuppercasecreatejs

Need to change text to upper case in JavaScript - createJs


I'm new to JavaScript and I have an HTML page with JavaScript where I need to show the text in a field with text "test text tuu" to upper case. I have tried to change it so:

this.harmonicField = new cjs.Text("test text tuu", "24px 'Fort Medium'", "#FFFFFF").toUpperCase();

and also like this:

this.harmonicField = this.harmonicField.toUpperCase();

but none of the commands work. When use these commands I don't see there anything - no text. Without the command toUpperCase()it works.

I have post it on pastebin.com (JavaScript and HTML):

How do I change the input text to upper case?


Solution

  • I'll try to answer clearly.
    toUpperCase is only applied to the String it cannot be applied directly to an Object as you trying to do.
    try something like this (i'm assuming you're using createJs library):

    var text = "test text tuu".toUpperCase();
    this.harmonicField = new createjs.Text(text, "24px 'Fort Medium'", "#FFFFFF");
    

    So you don't apply toUpperCase to the object but to a string.
    Also using this is always confusing but i think this could work:
    this.harmonicField.text = String(this.harmonicField.text).toUpperCase();

    In your case this old question from 2013 offers many good pointers in my opnion!