title: How do I capitalize the first letter of each text input in javaScript?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1026069/capitalize-the-first-letter-of-string-in-javascript">Capitalize the first letter of string in JavaScript</a>  </p>
  </blockquote>
  
  
  
  <p>This is may code so far. I would like the FIRST_Name and LAST_Name fields to capitalize the first letter and have all other letters small:</p>
  
  <p>Also, I am unfamiliar with javaScript so I am not exactly sure what I am doing.</p>
  
  <p><strong>latest edit. What is wrong with this code?</strong></p>
  
  <pre><code>    &lt;HTML&gt;
  &lt;HEAD&gt;
  &lt;TITLE&gt;&lt;/TITLE&gt;
  &lt;script language="javascript" type="text/javascript"&gt;
  &lt;!--
  function CheckForm()
  
  formObj.FIRST_Name.value = titleCase(formObj.FIRST_Name.value);
  formObj.LAST_Name.value = titleCase(formObj.LAST_Name.value);
  
  function titleCase(str) {
      var words = str.split(/\s+/);
      for (var i=0; i&lt;words.length; i++)
          words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1);
      return words.join(" ");
  }
  
  
  {
    var formObj = document.getElementById("Data");
    var firstname = formObj.FIRST_Name.value;
    var lastname = formObj.LAST_Name.value;
  
  
      if(notEmpty(formObj.FIRST_Name, "Please enter your first name")){       
      if(notEmpty(formObj.LAST_Name,"Please enter your last name")){  
      if(titleCase(formObj.FIRST_Name)            
  
      return true;}}
  
      return false;
      }
  
  function notEmpty(elem, helperMsg){
      if(elem.value.length == 0){
          alert(helperMsg);
          elem.focus(); // set the focus to this input
          return false;
      }
      return true;
  }
  
  
  &lt;/script&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
  &lt;div style="background: #CCCC99"&gt;
  &lt;HR&gt;&lt;FORM id="Data" onsubmit="return CheckForm()" action="post to server" method=post&gt;
  &lt;P&gt;First Name: &lt;input type=text name=FIRST_Name maxlength=15 size=15&gt;
     Last Name:  &lt;input type=text name=LAST_Name maxlength=15 size=15&gt;&lt;/P&gt;
  &lt;input type=submit value="Submit Products Registration Form" style="width: 220px"&gt;&lt;input type=reset value="Reset"&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  &lt;/BODY&gt;
  &lt;/HTML&gt;
  </code></pre>