Solved

Help on Capitalize function in asp.

Posted on 2002-03-20
8
319 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

16 Experts available now in Live!

Get 1:1 Help Now