Capiataloze Words - not working in IE

Posted on 2008-11-04
Last Modified: 2012-05-05
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('');
Question by:Jester_48
    LVL 15

    Expert Comment

    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

    LVL 24

    Accepted Solution

    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()});

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    This article shows how to read a single webpage's HTML into a string variable, and it also shows how to automate a sequence so you can read and process a list of webpages.  I was tasked with reading and parsing a series of webpages to collect some s…
    In my daily work (mainly using, I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now