• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

Make an Input type text all caps?

I have a field - call it Name - that when the user types a value into it, the value should be displayed as all capital letters.  How do I do that?

allie
0
allie
Asked:
allie
  • 7
  • 6
  • 6
  • +2
1 Solution
 
thunderchickenCommented:
???

in ASP...

<%
  name = "Hello"
  Response.write ucase(name)
%>
0
 
mgfranzCommented:
You should be asking the JavaScript group this question...  

What you are trying to do is client-side control of a form field, probably using the UpperCase object;

object.toUpperCase( );

Maybe like this, it still requires a "submit";

<script language="javascript">
//--------------------------------------------------------
// setFieldsToUpperCase(input_object)
//   Sets value of form field toUpperCase() for all fields passed
//--------------------------------------------------------

function setFieldsToUpperCase() {
     for (var i=0; i<arguments.length; i++) {
          var obj = arguments[i];
          obj.value = obj.value.toUpperCase();
          }
     }
</script>

...

<TABLE WIDTH=100% BORDER=1 CELLSPACING=0 CELLPADDING=2>
<TR BGCOLOR="#eeeeee">
     <TD><TT>setFieldsToUpperCase(input_object)</TT></TD>
</TR>
<TR BGCOLOR="#ffffff">
     <TD>
     <INPUT NAME="setFieldsToUpperCase_1" SIZE=15> <INPUT NAME="setFieldsToUpperCase_2" SIZE=15> <INPUT TYPE="button" CLASS="button" NAME="setFieldsToUpperCase_3" VALUE="setFieldsToUpperCase()" onClick="setFieldsToUpperCase(document.forms[0].setFieldsToUpperCase_1,document.forms[0].setFieldsToUpperCase_2)">
     </TD>
</TR>
</TABLE>

Again, check with the JavaScript group to see if it can be done on a keystroke...
0
 
raizonCommented:
Use stylesheets.

<style>
input {font-variant: small-caps;}
</style>
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
mgfranzCommented:
I think he wants each letter to be converted to UCase when the key is stroked...

Sounds like a good DHTML project...
0
 
mgfranzCommented:
Or;

<input type="text" name="myText" onKeyPress="changeVal()">

<script type="text/javascript" language="JavaScript">
s1 = new String(myForm.myText.value)

function changeVal() {
     s1 = "You pressed a key"
    myForm.myText.value = s1.toUpperCase()
}

</script>
0
 
mgfranzCommented:
[damn I'm good...]  ;-)
0
 
raizonCommented:
lol mgfranz

the style sheet will show the text as being uppercase.  So when the key is stroked you see an uppercase letter.
0
 
mgfranzCommented:
Full code, (forgot the <form>)

<body>
<form action="" method="POST" id="myForm" >
<input type="text" name="myText" onKeyPress="changeVal()">

<script type="text/javascript" language="JavaScript">
s1 = new String(myForm.myText.value)

function changeVal() {
     s1 = "You pressed a key"
    myForm.myText.value = s1.toUpperCase()
}

</script>
</form>
</body>
0
 
ebosscherCommented:
mgfranz, the problem with that solution is that it happens on keypress, or when the key goes down, what you would really need is a solution where it happened on keyup

here ya go:

<html>
<head>
<body>
<form name="FormName">
Enter your value here: <input type="text" onKeyUp="javascript:this.value = this.value.toUpperCase();">
</form>
</body>
</html>

similar, but different
0
 
allieAuthor Commented:
Got it!  I didn't want to use document level style sheets actually, since there's more than one field on the screen and I just needed that one field to be in caps.  But using your idea I did the following:

<style>
#caps {font-variant: small-caps;}
</style>
<input type="text" size="10" maxlength="10" name="UName" id="caps">

Works beautifully, thanks!!

allie
0
 
raizonCommented:
:-)

Glad to help.
0
 
ebosscherCommented:
so allie, you didn't actually need caps, what you really needed was for it to _look_ like caps?  Your data will still not be in caps that way... but I guess if that's what you want....
0
 
allieAuthor Commented:
ebosscher-

You must be a prophet!  Yeah, we just found that problem.  I thought it WAS in caps since that's how it appeared.  However, I already converted using the toUpperCase() function on submit.  Thanks!!

allie
0
 
raizonCommented:
I have no objection to giving the points to ebosscher since it was his solution you ended up using.
0
 
mgfranzCommented:
So in that case thunderchickens original comment would have been correct also...

Thanks for the help ebosscher.
0
 
allieAuthor Commented:
Actually, it wasn't... I used a combo of your's and mgfranz (since his was the first I saw with the toUppercase() function).  The code now looks like this:

<style>
#caps {font-variant: small-caps;}
</style>
<input type="text" size="10" maxlength="10" name="UName" id="caps">
<%
var sName= new String(Request("UName"));

//If filled out page is being loaded, process
if( sName!= "" && sName!= "undefined")
   sName = new String(sName.toUpperCase());
//Some other code
%>

However, if anyone feels that someone else should get some points I'm open to that idea.  Thanks to everyone for all your help though!!

allie


0
 
raizonCommented:
since you are not using my solution.  It would not be fair to the other experts here who's solution/combination of solutions you are using.


my apologies to allie, I forgot to mention that since my solution was w/style sheets that it was only appearance would be capitalized.

0
 
mgfranzCommented:
A split would be appropriate...
0
 
raizonCommented:
allie,

You'll probably want to post a 0 point question in community support with a reference to this question, and what you would like to do.

0
 
ebosscherCommented:
Look,

Some day, when I'm short on points, or I mess up giving an answer just forgive me the oversight and I'm happy..  I'm not here for the points.. I'm here for the help.

I say leave it the way it was, or give it to mgfranz and raizon (mgfranz and my answers were very similer, and he posted first)

Cheers
0
 
allieAuthor Commented:
*Grin*  Everyone's so accomodating... OK, here's what I'll do - I'm going to post in ComSupport and ask them to split the points on this question between raizon and mgfranz.  In the meantime, I'm going to post just a question here "Points for ebosscher".  That way since all three of you helped, you all get something for it.  I really do appreciate your efforts guys.  Thanks!!

allie
0
 
allieAuthor Commented:
On second thought, I'll just let comSupport do it all... that way I know it all gets done right!  Thanks!

allie
0
 
allieAuthor Commented:
OK guys, here's what we're doing - I'm going to post 25 point "questions" here for ebosscher and mgfranz.  Go ahead and post an "answer" and the points will transfer to you.  Thanks for your help!

allie
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

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