Capiataloze Words - not working in IE

I ma using teh following to capitalize letters in words, works great except in ie, in ie the divider is not retained,

so in ie sean micheal becomes Seanmicheal


function capitalizeMe(objFormField) {
      var arrWords=objFormField.value.toLowerCase().split(/(\s+|\-|\.|\')/);
      for(i=0;i<arrWords.length;i++){
              arrWords[i]=arrWords[i].substr(0,1).toUpperCase()+arrWords[i].substr(1)
            }
      objFormField.value = arrWords.join('');
}
LVL 25
James RodgersWeb Applications DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tomarse111Commented:
why dont you try:
<script type="text/javascript">
function capWords() {
var inputString = document.form1.instring; // The input text field
var outputString = document.form1.outstring; // The output text field
var tmpStr, tmpChar, preString, postString, strlen;
tmpStr = inputString.value.toLowerCase();
stringLen = tmpStr.length;
if (stringLen > 0)
{
  for (i = 0; i < stringLen; i++)
  {
    if (i == 0)
	{
      tmpChar = tmpStr.substring(0,1).toUpperCase();
      postString = tmpStr.substring(1,stringLen);
      tmpStr = tmpChar + postString;
    }
    else
	{
      tmpChar = tmpStr.substring(i,i+1);
      if (tmpChar == " " && i < (stringLen-1))
	  {
      tmpChar = tmpStr.substring(i+1,i+2).toUpperCase();
      preString = tmpStr.substring(0,i+1);
      postString = tmpStr.substring(i+2,stringLen);
      tmpStr = preString + tmpChar + postString;
      }
    }
  }
}
outputString.value = tmpStr;
}
</script>
<body id="doc">
	<form name="form1" method="post">
<input name="instring" type="text" value="this is the text string" size="30">
<input type="button" name="Capitalize" value="Capitalize >>" onClick="capWords();">
<input name="outstring" type="text" value="" size="30">
</form>
</body>

Open in new window

0
James RodgersWeb Applications DeveloperAuthor Commented:
if you look at my code you will see that i need it to work with more than just spaces, i also need it to work with apostrophe, hyphen and periods, that's the problem i can get it top work with jst spaces but adding in the other items makes it non functional in IE


i have replaced my code with this

function setProperCase(objFormField) {
      objFormField.value=objFormField.value.toLowerCase().replace(/(^\s*\w|[\s\.\-\']\s*\w)/g,function(c){return c.toUpperCase()});
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.