Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make the Alphabet enter capital if there is a space before it when entering text in the textbox

I want to make the ALPHABET capitalize entered by the user in the textbox if there is a space before it.

Example user writes "test new" so "n" should be a capital and it will be so smooth that it feels like the user pressed the shift key

I think we can do the same in keydown event (jquery)

The code is something that i tried is:

$('.name').live("keydown", function (e) {
  try {
    if ($('.name').val().length > 1) {
      if ($('.name').val().substring($('.name').val().length - 1) == " ") {
        // HERE can we do something like e.shift key etc to get desired result
      }
    }
  } catch (err) {
    alert(err);
  }
});
like image 560
Moons Avatar asked Dec 13 '22 04:12

Moons


1 Answers

Alternative

​.name {
    text-transform:capitalize;
}
like image 189
Alex K. Avatar answered Dec 14 '22 18:12

Alex K.