Solved

Help on Capitalize function in asp.

Posted on 2002-03-20
8
323 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Button to go back 3 39
Asp in script 6 46
Converting Stored Procedure to SQL Statement 5 44
calculate days away 11 29
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

726 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