?
Solved

Convert All Upper case to mixed case......

Posted on 2004-04-23
11
Medium Priority
?
3,271 Views
Last Modified: 2008-01-16
Does anybody know how to convert a string that is all in uppercase to a mixed case string in javascript. I know how to do this in PHP but I need to do this with javascript. I can't seem to find anything to do this.

Thanks
Cal
0
Comment
Question by:calzone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 9

Expert Comment

by:j3one
ID: 10902979
Microsoft word will change it all to lowercase, then you can go back through and hit the uppercase parts...
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 10903004
I do not understand this question, could you give an example.
0
 

Author Comment

by:calzone
ID: 10903094
I want to do this with a javascript function or command on a web page. I have a variable on a web page that is all uppercase. And I want to convert it to have The first letter of a word uppercase and the remaining letters in the word lowercase.

CONVERT THIS TEXT

into

Convert This Text
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 10

Expert Comment

by:Bustarooms
ID: 10903193
<script language="Javascript">
function firstLetter_Upper(theWord){
   var words = theWord.split(' ');
   var newWord='';
    for(i=0; i < words.length; i++)
        newWord += words[i].charAt(0).toUpperCase() + words[i].substring(1,words[i].length) + ' ';

alert(newWord);
return newWord;

}
</script>
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 10903267
this is shorter

<script language="Javascript">
function firstLetter_Upper(theWord){
 newWord=theWord.replace(/^(.)/,function (d){return d.toUpperCase()})
 return newWord;
}

alert(firstLetter_Upper('abc'))
</script>
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 10903300
<script language="Javascript">
function firstLetter_Upper(theWord){
 theWord=' '+theWord
 newWord=theWord.replace(/ (.)/g,function (d){return d.toUpperCase()})
 return newWord.replace(/ /,'');
}

alert(firstLetter_Upper('abc def ghi'))
</script>
0
 

Author Comment

by:calzone
ID: 10903499
Both of these functions are working if you start from a word that is all lowercase. But if you start from a word that is all uppercase they do not work. I am starting with all uppercase and need to get first letter upper and remaining letters lower.

Thanks
Cal
0
 
LVL 25

Expert Comment

by:devic
ID: 10903510
if i undestood good, this wants calzone
=============================
<script>
function firstLetter_Upper(str)
{
       var strArr=str.split(" ");
       for(var i=0;i<strArr.length;i++)
       strArr[i]=strArr[i].toLowerCase().replace(/^([ a-z])/g,function (d){return d.toUpperCase()})
       return strArr.join(" ");
}

alert(firstLetter_Upper('CONVERT THIS TEXT '))
</script>
0
 
LVL 10

Accepted Solution

by:
Bustarooms earned 500 total points
ID: 10903519
ahhhhh good point

<script language="Javascript">
function firstLetter_Upper(theWord){
   theWord = theWord.toLowerCase();
   var words = theWord.split(' ');
   var newWord='';
    for(i=0; i < words.length; i++)
        newWord += words[i].charAt(0).toUpperCase() + words[i].substring(1,words[i].length) + ' ';

alert(newWord);
return newWord;

}
</script>
0
 

Author Comment

by:calzone
ID: 10903836
Works great.

Thanks for the help Bustarooms.

Cal
0
 
LVL 25

Expert Comment

by:devic
ID: 10903842
and my? doesn't work?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

649 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