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+|\-|\.|\')/);
      objFormField.value = arrWords.join('');
LVL 25
James RodgersWeb Applications DeveloperAsked:
Who is Participating?
James RodgersConnect With a Mentor Web 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()});
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;
      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;
<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">

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.