0

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);
}
JMP
  • 4,417
  • 17
  • 30
  • 41
  • Does this answer your question? [Convert JavaScript String to be all lowercase](https://stackoverflow.com/questions/154862/convert-javascript-string-to-be-all-lowercase) – rx2347 May 14 '23 at 10:57
  • You could have looked in the documentation :) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase – Kokodoko May 14 '23 at 10:59

2 Answers2

2

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"
Jayden
  • 46
  • 3
  • I must confess that I'm up-voting mostly because of the entertainment value of "*THIS TEXT IS FULLY LOWER CASE*," though posting a correct answer is also useful. – David Thomas May 14 '23 at 16:49
0

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
}
  • Hi, your answer may address the question; however, try to improve it adding an explanation, or a link, so others can confirm that is a good answer (useful for the community). Read [how to answer](https://stackoverflow.com/help/how-to-answer) – pierpy May 14 '23 at 14:25