Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 329
  • Last Modified:

Help on Capitalize function in asp.

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
Leon Summers
Asked:
Leon Summers
  • 3
  • 2
  • 2
  • +1
1 Solution
 
thirdCommented:
if you're not planning x-browser, use css.

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

tested IE5, NS6.2
0
 
AlfaNoMoreCommented:
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
 
Leon SummersAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
AlfaNoMoreCommented:
Seems a bit pointless to me, as an email address is case insensitive?
0
 
Leon SummersAuthor Commented:
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
 
fritz_the_blankCommented:
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
 
Leon SummersAuthor Commented:
please!!!!
0
 
fritz_the_blankCommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now