473,386 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Auto-Capitalize Problem

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

Jul 23 '05 #1
4 1897
<sa**@centric.net> skrev i meddelandet
news:11**********************@f14g2000cwb.googlegr oups.com...
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.

--
Joakim Braun
Jul 23 '05 #2
sa**@centric.net wrote:
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();
">

--
Rob
Jul 23 '05 #3
s...@centric.net wrote:
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/cs.../texttrans.htm

Jul 23 '05 #4
JRS: In article <11**********************@f14g2000cwb.googlegroups .com>
, dated Wed, 23 Mar 2005 10:42:13, seen in news:comp.lang.javascript,
sa**@centric.net 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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Manlio Perillo | last post by:
Hi. This post follows "does python have useless destructors". I'm not an expert, so I hope what I will write is meaningfull and clear. Actually in Python there is no possibility to write code...
1
by: Lew | last post by:
Hi all, I'm trying to create a page that has a user-selectable page auto-refresh option (IE 5.5). Essentially, it's a page that contains a checkbox, when the user checks the checkbox, I'd like...
5
by: Robert Downes | last post by:
I'm using the following in a page that I'm testing in Mozilla: p.actionLinkBlock {border: 1px #000000 dashed; padding: 0.2cm; width: auto} But the dashed border is extending to the right-edge...
9
by: Alan Mackenzie | last post by:
To all those who use (X)Emacs's CC Mode to edit C, C++, Java, Objective-C, Pike, AWK or IDL: To help direct the development of CC Mode, it would be useful to find out how people use the...
20
by: Vijay Kumar R. Zanvar | last post by:
Hello, Unlike register, auto keyword can not be used to declare formal parameter(s). Is there any specific reason for this? Kind regards, Vijay Kumar R. Zanvar
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
7
by: Brian | last post by:
hello, I am looking for a way to auto refresh a web page that I created, but also let the user choose to stop the auto refresh. I can not figure out how to stop the auto refresh. Any help would...
5
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if...
22
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly...
21
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.