Search the Site

Sponsors

bottom corner

Convert text to upper or lower case

This note demonstrates a simple event handler to change text to upper or lower case using Javascript.

This page is filed under keyword(s): javascript.

To do so, simply make use of the toUpperCase() or toLowerCase() methods. For example:

<input type="text" name="myField" id="myField" size="20" onKeyup="javascript:this.value=this.value.toUpperCase();"> : To Upper

<input type="text" name="myField" id="myField" size="20" onKeyup="javascript:this.value=this.value.toLowerCase();"> : To Lower

Below is the working sample:

 To Upper

 To Lower

If you do not wish to run it for each key-up such as in this example, try the onChange event, which will only fire when the user leaves the input field.

Did you find this page useful? Please consider browsing other articles or subscribing to the RSS feed to keep up with latest.

This page is filed under keyword(s): javascript.
Author: C. Peter Chen
Last updated: 18 Sep 2008

bottom corner