skip to Main Content

I’m using a button to copy all text from an "input text area", but I need the text to be in uppercase and the script to format everything in lowercase.

How to make it uppercase?

function myFunction() {
        // Get the text field
        var copyText = document.getElementById("myInput");
        // Select the text field
        copyText.select();
        copyText.setSelectionRange(0, 99999); // For mobile devices
        // Copy the text inside the text field
        navigator.clipboard.writeText(copyText.value);
}

2

Answers


  1. You can use the .toLowerCase() And .toUpperCase()functions to modify a string to be either fully lower or upper case

    let text = "this text is fully lower case"
    
    console.log(text.toUpperCase()) // logs: "THIS TEXT IS FULLY LOWER CASE"
    
    Login or Signup to reply.
  2. You can try this, see the edit in last line:

    function myFunction() {
            // Get the text field
            var copyText = document.getElementById("myInput");
            // Select the text field
            copyText.select();
            copyText.setSelectionRange(0, 99999); // For mobile devices
            // Copy the text inside the text field
            navigator.clipboard.writeText(copyText.value.toLocaleLowerCase()); // Add this
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search