I have this code:
[B]function addressmasking()
{
var sContents = “oaklands street, uperman, london”
var temp = sContents.charAt(0).toUpperCase() + sContents.substr(1).toLowerCase() );
}[/B]
The code above will change the sContents to “Oaklands street…” However i need the code to put captial letters infront of every word. I know this is probably done using a loop but my coding skills aren’t that good.
Any ideas on this?
Is the address going to be put into a database? If so what server-side language are you using?
Seems like CSS would be much easier. Just add this to wherever the text is gonna be displayed
text-transform:capitalize;
This code is working in Firefox and Internet Explorer.
<script type="text/javascript">
var s = "The Time Through Ages. In the Name of Allah, Most Gracious, Most Merciful. 1. By the Time, 2. Verily Man is in loss, 3. Except such as have Faith, and do righteous deeds, and (join together) in the mutual enjoining of Truth, and of Patience and Constancy."
var words= s.split(/\\s/);
alert(words);
for(var i=0; i< words.length; i++){
words[i]= words[i].charAt(0).toUpperCase() + words[i].substr(1).toLowerCase();
}
alert(words.join());
</script>
http://www.w3schools.com/js/js_obj_array.asp
See http://javascript.about.com/library/blcase.htm for a way to add a toCapitalCase method that you can use in place of toLowerCase to get what you want.