Results 1 to 3 of 3

Thread: convert string to uppercase value

  1. #1
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default convert string to uppercase value

    Quote Originally Posted by Jus S
    How do I use anonymous functions to create an input field that converts the value into uppercase onblur()?
    research the .toUpperCase() function

    Code:
    var a = "this is some text";
    a.toUpperCase() 
    /* will give you -- THIS IS SOME TEXT */
    to take that and make a function to use in a script

    Code:
    function convertToUpper(str, el)
    {
         document.getElementById(el).value = str.toUpperCase();
    }
    Code:
    <input type="text" name="_something_" id="_id_" value="" onblur="javascript:convertToUpper(this.value, '_id_')">

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,192 Times in 3,155 Posts
    Blog Entries
    12

    Default

    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):

    Code:
    <input type="text" onblur="(function(){this.value = this.value.toUpperCase();}).apply(this);">
    But I believe this also qualifies as anonymous:

    Code:
    <input type="text" onblur="this.value = this.value.toUpperCase();">
    And I know it will work in any modern browser.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Though John certainly provides an aide.

    I wonder what's the problem with CSS:
    Code:
    text-transform:uppercase;
    ...besides the obvious that the (real) value is not capitalized.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •