Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make first letter uppercase

Status
Not open for further replies.

GiddyRob

Programmer
Aug 25, 2005
37
GB
I would like the first letter of a word to be in uppercase. I want it to do it when a form is submitted. The user will input some writing in a textfield then when the form is submitted it changes the first letter. This will happen before it goes into the database. I am quite new to javascript and I have used a complex sorting js script. It is great but it doesn't ignore case.

Anyone know a method to do this?

Cheers

Rob
 
Code:
<script language="javascript">
function capitalizeFirst(str) {
   if (str.length) {
      if (str.length == 1) {
         str.value = str.value.toUpperCase();
      }
      else {
         str.value = str.value.substr(0, 1).toUpperCase() + str.value.substr(1, str.length - 1);
      }
   }
   return true;
}
</script>
<form onsubmit="return capitalizeFirst(document.getElementById('txt'))">
<input type="text" id="txt">
<input type="submit" value="submit">
</form>

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top