How to Change All textbox or textfield values to upper case using javascript


I was searching for a method to get all the text boxes and text field data in a web page and change the values to upper case using java script, but couldn’t find a good script.

So I decided to write my own script. You can change this to fit your needs. This will be useful to format the form inputs automatically.


//function to check and change all text field values to upper case
function changeAllToUpper(){

var inputs = document.getElementsByTagName(‘input’);    // get all the text boxes
for(var k=0;k<inputs.length;k++)
{
var input = inputs[k]
if(input.type!= ‘text’) continue;
input.value=input.value.toUpperCase();  // make values uppercase
}

var textboxes = document.getElementsByTagName(‘textarea’);  // get all the text areas

for(var l=0;l<textboxes.length;l++)
{
var textbox = textboxes[l]

textbox.value=textbox.value.toUpperCase(); // make values upper case
}

}

you can call this function when clicking the form submit button like this,


onclick="javascript:changeAllToUpper();"

Some Suggestions

  • you can do any text modification using this script before submitting. (make lower case, camel case, or you can even use this for validate and update the data)
  • remove any unwanted symbols or characters easily without any server load.

Hope this code will be useful to you. let me know what you think. 🙂

Advertisements

One thought on “How to Change All textbox or textfield values to upper case using javascript

Let me know what you think .. :)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s