Home : Internet : JavaScript : Text : Uppercase

Convert Text to Uppercase

Converting a text string to uppercase is very easy using the JavaScript toUpperCase() method. The following example shows how this works:

This script takes the input from the first text field and outputs it to the second. You can adapt the script to accept and output the string in other ways.

Place the following code in the document head:

function makeUppercase() {
document.form1.outstring.value = document.form1.instring.value.toUpperCase();
}

Place the following code in the document body. This includes two text fields (one for the input and one for the resulting output) and a button to initiate the conversion:

<form name="form1" method="post">
<input name="instring" type="text" value="this is the text string" size="30">
<input type="button" name="Convert" value="Make Uppercase >>" onClick="makeUppercase();">
<input name="outstring" type="text" value="" size="30">
</form>