...

View Full Version : Block Capitals - HELLO to Hello etc..



howie2009
07-22-2009, 01:51 PM
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:thumbsup:

howie2009
07-22-2009, 02:00 PM
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>

Philip M
07-22-2009, 02:17 PM
Wow! A long-winded way of doing that!


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

venegal
07-22-2009, 04:18 PM
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:


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

VIPStephan
07-22-2009, 06:09 PM
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.)

Philip M
07-22-2009, 06:32 PM
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.

howie2009
07-23-2009, 10:22 AM
Thanks a million guys!!! Much appreciated.

:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum