Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts

    Block Capitals - HELLO to Hello etc..

    Hi Guys,
    Does anyone have code for changing uppercase characters in a word so that if a user types in all UPPERCASE only the 1st character stays in uppercase and the rest are converted to lowercase eg "100% FREE IPODS" would be converted to "100% Free Ipods".
    Thanks

  • #2
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts
    Found it on http://www.bestdownloadsites.com/first-letter-uppercase
    Thanks


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    <HTML>
    <HEAD>
    <META NAME="Generator" CONTENT="TextPad 4.4">
    <LINK href="general.css" rel="stylesheet" type="text/css">
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Original: William Humphreys (billy@technical-solutions.co.uk) -->

    <!-- Begin
    function changeCase(frmObj) {
    var index;
    var tmpStr;
    var tmpChar;
    var preString;
    var postString;
    var strlen;
    tmpStr = frmObj.value.toLowerCase();
    strLen = tmpStr.length;
    if (strLen > 0) {
    for (index = 0; index < strLen; index++) {
    if (index == 0) {
    tmpChar = tmpStr.substring(0,1).toUpperCase();
    postString = tmpStr.substring(1,strLen);
    tmpStr = tmpChar + postString;
    }
    else {
    tmpChar = tmpStr.substring(index, index+1);
    if (tmpChar == " " && index < (strLen-1)) {
    tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
    preString = tmpStr.substring(0, index+1);
    postString = tmpStr.substring(index+2,strLen);
    tmpStr = preString + tmpChar + postString;
    }
    }
    }
    }
    frmObj.value = tmpStr;
    }
    // End -->
    </script>

    </HEAD>

    <BODY Background=../graphics/grayback.jpg>
    <center><BR><BR><BR>
    <form name=form>
    <input type=text name=box value="type in here!">
    <input type=button value="Convert" onClick="javascript:changeCase(this.form.box)">
    </form>

    </center>
    </BODY>
    </HTML>

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Wow! A long-winded way of doing that!

    Code:
    <script type = "text/javascript">
    
    var str = "100% FREE IPODS"
    str = str.toLowerCase().replace(/\b[a-z]/g,function(w){return w.toUpperCase()});
    document.write(str);   // 100% Free Ipods
    
    </script>
    <script language=javascript> is long deprecated and obsolete. Use <script type = "text/javascript"> instead. The <!--
    and //--> tags have not been necessary since IE3 and always indicate ancient code.


    "The only thing to do with good advice is pass it on. It is never any use to oneself."- Oscar Wilde (Irish Poet, Novelist, Dramatist and Critic, 1854-1900)

  • Users who have thanked Philip M for this post:

    howie2009 (07-23-2009)

  • #4
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Or, if you don't want to change all the words to first letter uppercase and the rest lowercase, but only want to affect words that are writtin in all uppercase, you can use this:
    Code:
    <script type = "text/javascript">
    
    var str = "lowercase, CaMeLcAsE, UPPERCASE"
    str = str.replace(/\b([A-Z])([A-Z]*)\b/g, function(word, firstLetter, rest){return firstLetter + rest.toLowerCase()});
    document.write(str);   // lowercase, CaMeLcAsE, Uppercase
    
    </script>

  • Users who have thanked venegal for this post:

    howie2009 (07-23-2009)

  • #5
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,696
    Thanks
    6
    Thanked 1,011 Times in 984 Posts
    Quote Originally Posted by Philip M View Post
    Wow! A long-winded way of doing that!
    And from looking at the code a very outdated way either. (HTML 3.2? Come on! This is one of the disadvantages of the fact that the internet never forgets. People keep using really old and crappy code.)

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    We, I thought I had made that point. But by all means feel free to make it again.

    <script language=javascript> is long deprecated and obsolete. Use <script type = "text/javascript"> instead. The <!--
    and //--> tags have not been necessary since IE3 and always indicate ancient code.

  • #7
    Regular Coder howie2009's Avatar
    Join Date
    May 2009
    Location
    Ireland
    Posts
    204
    Thanks
    37
    Thanked 0 Times in 0 Posts
    Thanks a million guys!!! Much appreciated.



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •