Auto-Capitalize Problem

S

sams

First, I'll tell you up front that I am clueless when it comes to
Javascript. So I apologize if this question is off topic.


I have a nice little Javascript that capitalizes each field in my form
submissions. It looks like this:


<cfscript>
function CapFirst(str) {
var result = Trim(str);
var wordCount = ListLen(result," ");
var ProperString = "";
for(i=1;i LTE wordCount;i=i+1) {
ProperString = ProperString & " " & UCase(Left(ListGetAt(result,i,"
"),1)) & LCase(RemoveChars(ListGetAt(result,i," "),1,1));
} ProperString = Trim(ProperString);
return ProperString;}
</cfscript>


Then I display the results as follows:
#CapFirst(Session.Customer.FirstName)#


It works fantastic, except for some reason on my final form submission,

if someone enters an apostrophe in the field, it wants to repeat it 8
times. So the name "O'Brien" will look like "O''''''''brien". I can
live with the second character being lowercase, but the repeating
apostrophe's have to go.


Also, the amount of apostrophes returned is dependant on the number of
words in that field. So "Bob's and Ed's" would appear as
"Bob''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''s
And Ed''''''''''''''''s".


Any ideas?? Maybe adding an "if" statement to ignore the apostrophe's??
 
J

Joakim Braun

First, I'll tell you up front that I am clueless when it comes to
Javascript. So I apologize if this question is off topic.


I have a nice little Javascript that capitalizes each field in my form
submissions. It looks like this:


<cfscript>
function CapFirst(str) {
var result = Trim(str);
var wordCount = ListLen(result," ");
var ProperString = "";
for(i=1;i LTE wordCount;i=i+1) {
ProperString = ProperString & " " & UCase(Left(ListGetAt(result,i,"
"),1)) & LCase(RemoveChars(ListGetAt(result,i," "),1,1));
} ProperString = Trim(ProperString);
return ProperString;}
</cfscript>


Then I display the results as follows:
#CapFirst(Session.Customer.FirstName)#

Whatever this is, Javascript it ain't.
 
R

RobG

First, I'll tell you up front that I am clueless when it comes to
Javascript. So I apologize if this question is off topic.


I have a nice little Javascript that capitalizes each field in my form
submissions. It looks like this:


<cfscript>

I have zero experience of Cold Fusion, but if you really did
mean JavaScript, then why not use toUpperCase()?

<input type="text" size="20" onblur="
this.value = this.value.toUpperCase();
">
 
R

RobB

First, I'll tell you up front that I am clueless when it comes to
Javascript. So I apologize if this question is off topic.


I have a nice little Javascript that capitalizes each field in my form
submissions. It looks like this:


<cfscript>
function CapFirst(str) {
var result = Trim(str);
var wordCount = ListLen(result," ");
var ProperString = "";
for(i=1;i LTE wordCount;i=i+1) {
ProperString = ProperString & " " & UCase(Left(ListGetAt(result,i,"
"),1)) & LCase(RemoveChars(ListGetAt(result,i," "),1,1));
} ProperString = Trim(ProperString);
return ProperString;}
</cfscript>


Then I display the results as follows:
#CapFirst(Session.Customer.FirstName)#


It works fantastic, except for some reason on my final form submission,

if someone enters an apostrophe in the field, it wants to repeat it 8
times. So the name "O'Brien" will look like "O''''''''brien". I can
live with the second character being lowercase, but the repeating
apostrophe's have to go.


Also, the amount of apostrophes returned is dependant on the number of
words in that field. So "Bob's and Ed's" would appear as
"Bob''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''s
And Ed''''''''''''''''s".


Any ideas?? Maybe adding an "if" statement to ignore the
apostrophe's??

<style type="text/css">

input.cap {
text-transform: capitalize;
}

</style>
..............
<input class="cap"..../>

http://www.blooberry.com/indexdot/css/properties/text/texttrans.htm
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Wed, 23 Mar 2005 10:42:13, seen in (e-mail address removed) posted :
First, I'll tell you up front that I am clueless when it comes to
Javascript.
Plausible.

I have a nice little Javascript ???
that capitalizes each field in my form
submissions.

S in, T out.

for (T="", j=0, Sep = true ; j<S.length ; j++) {
C = S.charCodeAt(j)
if (Sep && C>96 && C<123) C -= 32 //1
Sep = C<33 || C==39 || C==45 //2
T += String.fromCharCode(C)
}

Follow the //1 line with lines treating lower-case letters outside the
range a..z - for example àáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ (which you may
not see correctly); there are many more.

Modify the //2 line for the characters after which a letter should be
capital.

Note that capitalisation of "cat's-meat potter-pirbright", "duke of
wessex" "macallen" "machinery" "o'sidney" "aesop's fables" will hive you
problems.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top