Solved

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

Posted on 2004-04-23
11
3,138 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 125 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

910 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

16 Experts available now in Live!

Get 1:1 Help Now