0

In web application. i have a user registration form, in that form when user enter his name the first letter of his name automatically first letter of his name convert into capital is there any script or any logic for this requirement. Thank you.

I write Javascript But it is giving error like Microsoft JScript runtime error:
Microsoft JScript runtime error: Object doesn't support this property or method

function capitaliseFirstLetter(obj)
{
    return obj.charAt(0).toUpperCase() + obj.slice(1);
}

<input type ="text" id ="txt"  onkeyup ="capitaliseFirstLetter(this)" />
Surya sasidhar
  • 29,607
  • 57
  • 139
  • 219
  • Have a look at this answer: http://stackoverflow.com/questions/1026069/capitalize-the-first-letter-of-string-in-javascript – Steve Nov 01 '11 at 10:39

2 Answers2

0

Hi if you can look outside the JavaScript then I think you can try

text-transform: capitalize;

apply the above style in your input element style and it's first later will become a capital I hope this is useful

Jasmin Raval
  • 184
  • 1
  • 5
  • 15
0

You could do this using client side script too, but as your tags say ASP.NET, I'll give you a server-side example.

static string UppercaseFirst(string s)
{
    if (string.IsNullOrEmpty(s))
    {
        return string.Empty;
    }
    return char.ToUpper(s[0]) + s.Substring(1);
}
Connell
  • 13,925
  • 11
  • 59
  • 92
  • ya thank you Connell Watkins, i try in machine and let you inform – Surya sasidhar Nov 01 '11 at 10:44
  • If you want all words in the string (not just the first word) to be with initial capital letter, you can also use `s = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s);`. For a person name, like `"john d. doe"`, this might be appropriate. – Jeppe Stig Nielsen Nov 16 '12 at 11:42