View Full Version : convert string to uppercase value

07-03-2008, 01:36 PM
How do I use anonymous functions to create an input field that converts the value into uppercase onblur()?

research the .toUpperCase() function

var a = "this is some text";
/* will give you -- THIS IS SOME TEXT */

to take that and make a function to use in a script

function convertToUpper(str, el)
document.getElementById(el).value = str.toUpperCase();

<input type="text" name="_something_" id="_id_" value="" onblur="javascript:convertToUpper(this.value, '_id_')">

07-03-2008, 03:56 PM
I don't think that's an anonymous function, but I could be wrong.

This certainly is an anonymous function (tested in FF 2 only, but may work in all or most modern browsers):

<input type="text" onblur="(function(){this.value = this.value.toUpperCase();}).apply(this);">

But I believe this also qualifies as anonymous:

<input type="text" onblur="this.value = this.value.toUpperCase();">

And I know it will work in any modern browser.

07-04-2008, 01:02 AM
Though John certainly provides an aide.

I wonder what's the problem with CSS:


...besides the obvious that the (real) value is not capitalized.