Jquery: Capitalize the first letter of string in Jquery

How to capitalize the first character of a string, but not change the case of any of the other letters?

by lakshmipriya001

HTML

First Name:
<input id="txtFirstName" name="txtFirstName" type="text" value="" />
</br>
</br>Last Name:
<input id="txtLastName" name="txtLastName" type="text" value="" />

JavaScript

$("#txtFirstName").keypress(function () {
      var _val = $("#txtFirstName").val();
      var _txt = _val.charAt(0).toUpperCase() + _val.slice(1);
      $("#txtFirstName").val(_txt);
  })

   $("#txtLastName").keypress(function () {
      var _val = $("#txtLastName").val();
      var _txt = _val.charAt(0).toUpperCase() + _val.slice(1);
      $("#txtLastName").val(_txt);
  })