Solved

Make an Input type text all caps?

Posted on 2002-05-07
23
308 Views
Last Modified: 2012-06-27
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
Comment
Question by:allie
  • 7
  • 6
  • 6
  • +2
23 Comments
 
LVL 11

Expert Comment

by:thunderchicken
Comment Utility
???

in ASP...

<%
  name = "Hello"
  Response.write ucase(name)
%>
0
 
LVL 18

Expert Comment

by:mgfranz
Comment Utility
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
 
LVL 5

Accepted Solution

by:
raizon earned 50 total points
Comment Utility
Use stylesheets.

<style>
input {font-variant: small-caps;}
</style>
0
 
LVL 18

Expert Comment

by:mgfranz
Comment Utility
I think he wants each letter to be converted to UCase when the key is stroked...

Sounds like a good DHTML project...
0
 
LVL 18

Expert Comment

by:mgfranz
Comment Utility
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
 
LVL 18

Expert Comment

by:mgfranz
Comment Utility
[damn I'm good...]  ;-)
0
 
LVL 5

Expert Comment

by:raizon
Comment Utility
lol mgfranz

the style sheet will show the text as being uppercase.  So when the key is stroked you see an uppercase letter.
0
 
LVL 18

Expert Comment

by:mgfranz
Comment Utility
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
 
LVL 6

Expert Comment

by:ebosscher
Comment Utility
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
 
LVL 2

Author Comment

by:allie
Comment Utility
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
 
LVL 5

Expert Comment

by:raizon
Comment Utility
:-)

Glad to help.
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 6

Expert Comment

by:ebosscher
Comment Utility
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
 
LVL 2

Author Comment

by:allie
Comment Utility
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
 
LVL 5

Expert Comment

by:raizon
Comment Utility
I have no objection to giving the points to ebosscher since it was his solution you ended up using.
0
 
LVL 18

Expert Comment

by:mgfranz
Comment Utility
So in that case thunderchickens original comment would have been correct also...

Thanks for the help ebosscher.
0
 
LVL 2

Author Comment

by:allie
Comment Utility
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
 
LVL 5

Expert Comment

by:raizon
Comment Utility
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
 
LVL 18

Expert Comment

by:mgfranz
Comment Utility
A split would be appropriate...
0
 
LVL 5

Expert Comment

by:raizon
Comment Utility
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
 
LVL 6

Expert Comment

by:ebosscher
Comment Utility
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
 
LVL 2

Author Comment

by:allie
Comment Utility
*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
 
LVL 2

Author Comment

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

allie
0
 
LVL 2

Author Comment

by:allie
Comment Utility
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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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 would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

7 Experts available now in Live!

Get 1:1 Help Now