I'm trying to do what I think it's a pretty simple thing but I'm having problems to make it work.
I have a form with some input fields that need to be transformed to title case (the first letter of each word need to be uppercase) while typing.
I found a function to do it, but it doesn't seem to work on the input field.
I also had found some fancy scripts like http://individed.com/code/to-title-case/ but there so much that I don't really need.
I'm using AngulasJS if that really matters.
function toTitleCase(str) {
        return str.replace(
            /\w\S*/g,
            function(txt) {
              return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
            }
        );
    }<div class="form">
    <h4>Part of a form</h4>
  <form class="form" name="form" method="post">
   <label for="username"><span class="required">*</span>Username:</label>
   <input id="username" type="text" name="username" autofocus onchange="form.output.value=toTitleCase(this.value)" onkeyup="form.output.value=toTitleCase(this.value)">
   <input class="login" type="submit" value="Save">
   </form>
</div>   
     
    