Solved

Help on Capitalize function in asp.

Posted on 2002-03-20
8
320 Views
Last Modified: 2008-03-17
I found a way of using the onblur=??? Capitalize function to change the first letter of every word in a text box to capital letters but now ive gone and lost the code and cant find it again.

Help if anyone knows how to do it or another way which doesnt take much code to do the same thing.

Leon.
0
Comment
Question by:Leon Summers
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 30

Expert Comment

by:third
ID: 6882076
if you're not planning x-browser, use css.

<input type="text" style="text-transform : capitalize">

tested IE5, NS6.2
0
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6882078
I'm not sure this is an ASP question, so here's a go using JavaScript:


function Capitalize(text) {
   var words = text.split(' ');
   for(i=0; i<words.length; i++) {
      var start = words(i).substring(0,1);
      var remain = words(i).substring(1, words(i).length);
      words(i) = start.toUpperCase() + remain;
   }
   return words.join(' ');
}

You'll have to check the substring's. I'm a bit hazy about the start and end positions, so might need some testing?
0
 
LVL 2

Author Comment

by:Leon Summers
ID: 6882111
I have tried both of the above but not managed to get them to work. I am currently using a javascript to capitalise the first letter which works for all text boxes except it wont capitalise a word like an email address properly. ie

Joe.bloggs@wherever.com

due to no space being between the names only a fullstop.

any ideas or easy solutions would be appreciated.

Leon.
0
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6882160
Seems a bit pointless to me, as an email address is case insensitive?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:Leon Summers
ID: 6882164
As the system emails out using these email addresses it looks a bit more professional if it looks right when the customer receives it. They seem to want it im quite happy as it is. As the original question states I did get it to work but after fiddling with the code I cant find it again.

It was one line which started with onblur="'Capitalize'" or something like this.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 6882492
Summers,

I have written some javascript code that does something that you might like:


-If the string is mixed case, it leaves it alone
-If the string is all upper case or all lower case does the following:

It capatalizes the first letter and goes through the string, and it checks to see what preceeds each letter. If it is another letter, it leaves the character alone; if it is anything other than a letter, i.e. a space, a symbol and etc., it capatalizes it.

I am heading to work in about an hour or so, and if you are interested, I'll post the code here.

Fritz the Blank
0
 
LVL 2

Author Comment

by:Leon Summers
ID: 6882516
please!!!!
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 20 total points
ID: 6882610
Here it is:

function properName(strField)
{
//This function adds capitals to each word in a string if the original text is
//all upper case or all lower case
     var bolMixedCase, strValue, strTempValue, arrName, strProperName
     bolMixedCase = true;
     strValue = eval('document.forms[0].' + strField + '.value');
     strTempValue = strValue.toUpperCase()
     if(strValue==strTempValue){
          bolMixedCase = false;
     }
     strTempValue = strValue.toLowerCase()
     if(strValue==strTempValue){
          bolMixedCase = false;
     }
     if(! bolMixedCase){
          arrName= new Array(strValue.length)
          for(intAt=0;intAt<strValue.length;intAt++){
               arrName[intAt] = strValue.substring(intAt,intAt + 1);
          }
          arrName[0] = arrName[0].toUpperCase()
          strProperName = arrName[0]
          for(i=1;i<arrName.length;i++){
               strTest = arrName[i-1];
               if(arrName[i-1].toUpperCase()<"A" || arrName[i-1].toUpperCase()>"Z"){
                    arrName[i] = arrName[i].toUpperCase();
               }else{
                    arrName[i] = arrName[i].toLowerCase();
               }
               strProperName = strProperName + arrName[i];
          }
          eval('document.forms[0].' + strField + '.value=strProperName');
     }
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
replace quotes with UTF-8 character 38 83
JSON error 4 51
Using querystring in a hyperlink 3 46
Auto Submit on dropdown box 14 52
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now