Solved

Help on Capitalize function in asp.

Posted on 2002-03-20
8
321 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6882160
Seems a bit pointless to me, as an email address is case insensitive?
0
 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

773 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