/    Sign up×
Community /Pin to ProfileBookmark

Proper Case lettering

Hi, i am trying to set this up so that if user enters his or her name with bunch of upper and lower cases there would be a message of some sort asking if the user wants to leave the name the way he wrote it if user clicks yes then name stays as it is if he clicks no then it will be changed to the proper casing which is coded in here:

[CODE]<!–Content–>
<form name=theForm id=theForm>
<input name=text1 id=text1 value=”” onchange=”this.value = PCase2(this.value);”>
<br>
<br>
<a href=”#” class=PageMenu style=”width:250;” onclick=”document.theForm.text1.value = PCase(document.theForm.text1.value);”><strong>Convert to Proper Case</strong></a>
<h3>
</textarea>
</form>
<!–End Content–>

<script>
function PCase(STRING)
{
var strReturn_Value = “”;
var iTemp = STRING.length;
if(iTemp==0){
return””;
}
var UcaseNext = false;
var test = STRING.indexOf(‘de ‘);
if(test != -1){
strReturn_Value += STRING.charAt(0).toLowerCase();
}else{
strReturn_Value += STRING.charAt(0).toUpperCase();
}
for(var iCounter=1;iCounter < iTemp;iCounter++){
if(UcaseNext == true){
strReturn_Value += STRING.charAt(iCounter).toUpperCase();
}
else{
strReturn_Value += STRING.charAt(iCounter).toLowerCase();
}
var iChar = STRING.charCodeAt(iCounter);
if(iChar == 32 || iChar == 45 || iChar == 46){
UcaseNext = true;
}
else{
UcaseNext = false
}
if(iChar == 99 || iChar == 67){
if(STRING.charCodeAt(iCounter-1)==77 || STRING.charCodeAt(iCounter-1)==109){
UcaseNext = true;
}
}
if(iChar == 39){
if(STRING.charCodeAt(iCounter-1)==79 || STRING.charCodeAt(iCounter-1)==111){
UcaseNext = true;
}
}
} //End For
return strReturn_Value;
} //End Function

</script>[/CODE]

please help me up setting up that message
what i was thinking about was saying something like :

[CODE]

function PCase2(STRING)
{
var strReturn_Value = “”;
var iTemp = STRING.length;
if(iTemp==0){
return””;
}
for(var iCounter=1;iCounter < iTemp;iCounter++){
var iChar = STRING.charCodeAt(iCounter);
if(iChar == 65 || iChar == 66 || iChar == 67 || iChar == 68 || iChar == 69 || iChar == 70 || iChar == 71 || iChar == 72 || iChar == 72 || iChar == 73 || iChar == 74 || iChar == 75 || iChar == 76 || iChar == 77 || iChar == 78 || iChar == 79 || iChar == 80 || iChar == 81 || iChar == 82 || iChar == 83 || iChar == 85 || iChar == 86 || iChar == 87 || iChar == 88 || iChar == 89 || iChar == 90){
alert(“Your name has upper and lower case lettering n Do you want to leave it like that n or else it will be changed to the proper format”);
return false;
}else{
Pcase(STRING);
}
}
return strReturn_Value;
}[/CODE]

but alert is not what i need and it surely is not the proper way to code it…
please Help
Alina

to post a comment
JavaScript

12 Comments(s)

Copy linkTweet thisAlerts:
@LogicianAug 01.2006 — Hi, i am trying to set this up so that if user enters his or her name with bunch of upper and lower cases there would be a message of some sort asking if the user wants to leave the name the way he wrote it if user clicks yes then name stays as it is if he clicks no then it will be changed to the proper casing which is coded in here:

[CODE]
if(iChar == 65 || iChar == 66 || iChar == 67 || iChar == 68 || iChar == 69 || iChar == 70 || iChar == 71 || iChar == 72 || iChar == 72 || iChar == 73 || iChar == 74 || iChar == 75 || iChar == 76 || iChar == 77 || iChar == 78 || iChar == 79 || iChar == 80 || iChar == 81 || iChar == 82 || iChar == 83 || iChar == 85 || iChar == 86 || iChar == 87 || iChar == 88 || iChar == 89 || iChar == 90)[/CODE]
[/QUOTE]
You missed out 84

There are better ways of doing this, but try:[CODE]if(iChar>=65 && iChar<=90)[/CODE]

but alert is not what i need and it surely is not the proper way to code it...[/QUOTE]You could use confirm()
Copy linkTweet thisAlerts:
@KorAug 01.2006 — have u considered a RegExp solution?

http://www.regular-expressions.info/tutorialcnt.html

or google for javascript regExp
Copy linkTweet thisAlerts:
@eidalina20authorAug 01.2006 — thank you guys for advices... i'll check that stuff out...

by the way would you be able to let me know what i should do for another posting i had under name: JS cookie help

on page 2 or so.... i would really appreciate any possible help you could give me... thank you
Copy linkTweet thisAlerts:
@eidalina20authorAug 02.2006 — ?

ok... can someone please help me with this...

i took the advice to use the confirm box... however i only want it to work when name is misspelled meaning if i write something like John Smith the pop up should not show up but if name was typed as joHn sMith then pop up....

the whole perpose for this is to check names like DeMorgan so that it would not become Demorgan after casing....

[CODE]function PCase2(STRING)
{
var iTemp = STRING.length;
if(iTemp==0){
return"";
}
for(var iCounter=1;iCounter < iTemp;iCounter++){
var iChar = STRING.charCodeAt(iCounter);
if(iChar){
var answer = window.confirm("The information you just entered has upper and lower casing n Click OK to leave your name as it is n by pressing Cancel the case will be changed");
if (answer == true){ //user clicked OK
return STRING;
}else{ // user clicked Cancel
return PCase(STRING);
}
}
}
}[/CODE]



like i need to code this somehow:

ike how would i say if upper case letter exists but not at 1st charecter and if all are upper case give an alert
Copy linkTweet thisAlerts:
@jalarieAug 02.2006 — Maybe this will get you going in the right direction:
<i>
</i>Name=prompt('Name','');
Items=Name.split(/ /);
IsOK='yes';
for (i=0; i&lt;Items.length; i++) {
Item=Items[i];
len=Item.length;
if (len &gt; 1) {
char=Item.substring(1,2);
if ((char &gt;= 'A') &amp;&amp; (char &lt;= 'Z')) {
IsOK='no';
}
}
alert(i+' '+len+' '+char+' '+Items[i]);
}
alert(IsOK);
Copy linkTweet thisAlerts:
@eidalina20authorAug 02.2006 — jalarie thank you for the code

but i don't really see how it can be used with my code... because you are using dif technique to it..

i'll explain one more time what iam trying to accomplish:

if names like Alina, James, Anna Maria are entered then there is no alert...

if names are AliNa, jaMes, MARIA, maria, DeMorgan.... then basically this line of code should pop out:

[CODE]var answer = window.confirm("The information you just entered has upper and lower casing n Click OK to leave your name as it is n by pressing Cancel the case will be changed");
if (answer == true){ //user clicked OK
return STRING;
}else{ // user clicked Cancel
return PCase(STRING);
}[/CODE]


i would greately appreciate if it was related to my code... because i am totally new to this and for me it's hard to modify things...

thank you ?
Copy linkTweet thisAlerts:
@jalarieAug 02.2006 — Maybe this will help better:
<i>
</i>function PCase2(STRING)
{
Items=STRING.split(/ /);
IsOK=true;
for (i=0; i&lt;Items.length; i++) {
Item=Items[i];
len=Item.length;
if (len &gt; 1) {
char=Item.substring(1,2);
if ((char &gt;= 'A') &amp;&amp; (char &lt;= 'Z')) {
IsOK=false;
}
}
alert(i+' '+len+' '+char+' '+Items[i]);
}
if (IsOK) { return STRING; }
AUMesg="The information you just entered has upper and lower casing n ";
AUMesg+="Click OK to leave your name as it is n ";
AUMesg+="by pressing Cancel the case will be changed";
AskUser=confirm(AUMesg);
if (AskUser) { return STRING; }
return PCase(STRING);
}
Copy linkTweet thisAlerts:
@eidalina20authorAug 02.2006 — hey thanx, but whatever you wrote only works for names like ALINA.... not alina or AliNa or aliNa ,,,,of DeMorgan...

basically if there is more than 1 upper case letter in the name entered ... message should pop up....

thank you very much ?
Copy linkTweet thisAlerts:
@eidalina20authorAug 02.2006 — this is what i had before your piece.. try it out...

[CODE]<!--Content-->
<form name=theForm id=theForm>
<input name=text1 id=text1 value="" onchange="this.value = PCase2(this.value);">
<br>
<br>
<a href="#" class=PageMenu style="width:250;" onclick="document.theForm.text1.value = PCase2(document.theForm.text1.value);"><strong>Convert to Proper Case</strong></a>
<h3>
</textarea>
</form>
<!--End Content-->

<script>
function PCase(STRING)
{
var strReturn_Value = "";
var iTemp = STRING.length;
if(iTemp==0){
return"";
}
var UcaseNext = false;
var test = STRING.indexOf('de ');
if(test != -1){
strReturn_Value += STRING.charAt(0).toLowerCase();
}else{
strReturn_Value += STRING.charAt(0).toUpperCase();
}
for(var iCounter=1;iCounter < iTemp;iCounter++){
if(UcaseNext == true){
strReturn_Value += STRING.charAt(iCounter).toUpperCase();
}
else{
strReturn_Value += STRING.charAt(iCounter).toLowerCase();
}
var iChar = STRING.charCodeAt(iCounter);
if(iChar == 32 || iChar == 45 || iChar == 46){
UcaseNext = true;
}
else{
UcaseNext = false
}
if(iChar == 99 || iChar == 67){
if(STRING.charCodeAt(iCounter-1)==77 || STRING.charCodeAt(iCounter-1)==109){
UcaseNext = true;
}
}
if(iChar == 39){
if(STRING.charCodeAt(iCounter-1)==79 || STRING.charCodeAt(iCounter-1)==111){
UcaseNext = true;
}
}
} //End For
return strReturn_Value;
} //End Function


function PCase2(STRING)
{
var iTemp = STRING.length;
if(iTemp==0){
return"";
}
for(var iCounter=1;iCounter < iTemp;iCounter++){
var iChar = STRING.charCodeAt(iCounter);
if(iChar>=65 && iChar<=90){
//do something here
}else{
var answer = window.confirm("The information you just entered has upper and lower casing n Click OK to leave your name as it is n by pressing Cancel the case will be changed");
if (answer == true){ //user clicked OK
return STRING;
}else{ // user clicked Cancel
return PCase(STRING);
}
}
}
}
</script>[/CODE]
Copy linkTweet thisAlerts:
@eidalina20authorAug 02.2006 — this is the code and how it works with your changes:

[CODE]
<!--Content-->
<form name=theForm id=theForm>
<input name=text1 id=text1 value="" onchange="this.value = PCase2(this.value);">
<br>
<br>
<a href="#" class=PageMenu style="width:250;" onclick="document.theForm.text1.value = PCase2(document.theForm.text1.value);"><strong>Convert to Proper Case</strong></a>
<h3>
</textarea>
</form>
<!--End Content-->

<script>
function PCase(STRING)
{
var strReturn_Value = "";
var iTemp = STRING.length;
if(iTemp==0){
return"";
}
var UcaseNext = false;
var test = STRING.indexOf('de ');
if(test != -1){
strReturn_Value += STRING.charAt(0).toLowerCase();
}else{
strReturn_Value += STRING.charAt(0).toUpperCase();
}
for(var iCounter=1;iCounter < iTemp;iCounter++){
if(UcaseNext == true){
strReturn_Value += STRING.charAt(iCounter).toUpperCase();
}
else{
strReturn_Value += STRING.charAt(iCounter).toLowerCase();
}
var iChar = STRING.charCodeAt(iCounter);
if(iChar == 32 || iChar == 45 || iChar == 46){
UcaseNext = true;
}
else{
UcaseNext = false
}
if(iChar == 99 || iChar == 67){
if(STRING.charCodeAt(iCounter-1)==77 || STRING.charCodeAt(iCounter-1)==109){
UcaseNext = true;
}
}
if(iChar == 39){
if(STRING.charCodeAt(iCounter-1)==79 || STRING.charCodeAt(iCounter-1)==111){
UcaseNext = true;
}
}
} //End For
return strReturn_Value;
} //End Function


function PCase2(STRING)
{
var Items=STRING.split(/ /);
var IsOK=true;
for (i=0; i<Items.length; i++) {
Item=Items[i];
var len=Item.length;
if (len > 1) {
var char=Item.substring(1,2);
if ((char >= 'A') && (char <= 'Z')) {
IsOK=false;
}
}
}
if (IsOK){
return STRING;
}
var answer = window.confirm("The information you just entered has upper and lower casing n Click OK to leave your name as it is n by pressing Cancel the case will be changed");
if (answer == true) {
return STRING;
}
return PCase(STRING);
}
</script>[/CODE]
Copy linkTweet thisAlerts:
@eidalina20authorAug 02.2006 — hey ok... i figured it out...it works fine ... the only thing i need to fix is to make sure that it recognizes names in only low case .. so like alina, steve etc... and would promp the user for the same error:

[CODE]
function PCase2(STRING)
{
var Items=STRING.split(/ /);
var IsOK=true;
for (var i=0; i<Items.length; i++) {
var string=Items[i];
for (var j=1; j<string.length; j++){
var iChar=string.charAt(j);
if ((iChar >= 'A') && (iChar <= 'Z')) {
IsOK=false;
}
}
}
if (IsOK == true){
return STRING;
}
var answer = window.confirm("The information you just entered has upper and lower casing n Click OK to leave your name as it is n by pressing Cancel the case will be changed");
if (answer == true) {
return STRING;
}
return PCase(STRING);
}[/CODE]



other than that... it worked amazingly.. thank you
Copy linkTweet thisAlerts:
@eidalina20authorAug 03.2006 — ok nevermind... i got it all working.... thank you
×

Success!

Help @eidalina20 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...