Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: auto capitalize textbox

  1. #1
    Join Date
    Jun 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question auto capitalize textbox

    I need a javascript that can auto capitalize the first character of the textbox. ie, if the name entered is john, once the focus is cleared, it should become John.

    Something similar to this code - http://www.pengoworks.com/workshop/js/mask/

    Please help.
    Last edited by jpaulraj; 07-12-2006 at 06:07 PM.

  2. #2
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Here ya go:

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function capitalize(form) {
            value = form.value;
            newValue = '';
            value = value.split(' ');
            for(var i = 0; i < value.length; i++) {
                    newValue += value[i].substring(0,1).toUpperCase() +
    value[i].substring(1,value[i].length) + ' ';
            }
            form.value = newValue;
    }
    </script>
    </head>
    <body>
    <form name="testform">
    <input type="text" name="testinput" onBlur="capitalize(this)">
    </form>
    </body>
    </html>

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <script type="text/javascript">
    String.prototype.toTitleCase = function() {
      var words = this.split(" ");
      for(var i = 0; i < words.length; ++i)
        words[i] = words[i].charAt(0).toUpperCase() + words[i].substring(1).toLowerCase();
      return words.join(" ");
    };
    </script>
    
    <input type="text" onblur="this.value = this.value.toTitleCase();">
    /EDIT: Drat, beaten to it
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    /EDIT: Drat, beaten to it
    there....there..... its ok....this is not a popularity contest nor a "first come first put to use" contest at least jpaulraj has an option to choose he he

  5. #5
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yes Twey, we are not in a warfare. The best thing is the script should work and both our scripts work!!!

    EDIT: Twey by the way did you realize that both our scripts use almost the same principal.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yes Twey, we are not in a warfare.
    Of course not, it's just irritating to post something you thought was highly relevant and helpful and then find out that someone else has already done so Not their faul, of course.
    Twey by the way did you realize that both our scripts use almost the same principal.
    Of course, there's basically only one way to achieve this.

    Watch the globals, by the way (gah, now that sounds like I'm vying for points -- just a tip )
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Jun 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks a million folks.. you all made my day.. truly appriciate the help.

  8. #8
    Join Date
    Jun 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    just one more stuff i used the ssn mask from this site -

    http://dotnetjunkies.com/WebLog/feel.../23/17365.aspx

    when i type a number 123456789 it masks it to 123-45-6789 that's perfect. Now i need to know if a user can enter just 4 digits of his ssn (last 4) so that the textbox should look like '- - 6789' (prepending it with two dash's if just 4 digits entered, if 9 digits entered then format the whole thing)

    Thanks again.

  9. #9
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    Of course not, it's just irritating to post something you thought was highly relevant and helpful and then find out that someone else has already done so Not their faul, of course.Of course, there's basically only one way to achieve this.

    Watch the globals, by the way (gah, now that sounds like I'm vying for points -- just a tip )
    Yea, I agree that's kinda embarrasing.

  10. #10
    Join Date
    Jun 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Quote Originally Posted by jpaulraj
    just one more stuff i used the ssn mask from this site -

    http://dotnetjunkies.com/WebLog/feel.../23/17365.aspx

    when i type a number 123456789 it masks it to 123-45-6789 that's perfect. Now i need to know if a user can enter just 4 digits of his ssn (last 4) so that the textbox should look like '- - 6789' (prepending it with two dash's if just 4 digits entered, if 9 digits entered then format the whole thing)

    Thanks again.
    Can anyone please help...

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
  •