3MRAN 3MRAN - 1 month ago 5x
jQuery Question

Change Text box value to Uppercase the first letter of every word separated by (.)

How can I change the value of textbox using jQuery/JavaScript before the form get submitted (before button clicked) when a user typed:

will.smith to Will.Smith

I have used the below code which only convert it Uppercase (entire string):

$('input[type=text]').val (function () {
return this.value.toUpperCase();

Keeping in mind I don't want to change it visually using CSS.

I hope someone can give me an idea on the same.

textBox.value = textBox.value.split('.').map(function(word) {
  return word[0].toUpperCase() + word.substr(1);

Or since you are using jQuery:

$('input[type=text]').val(function() {
  return this.value.split('.').map(function(word) {
    return word[0].toUpperCase() + word.substr(1);

I'm not sure what you want to do with the value? But I think you get the idea.

Also, to be on the safe side you could do something like word.substr(1).toLowerCase() which would make sure that only the first letter is capitalized.