What is the easiest way to convert the text in a text box to upper case as you are typing the letters?
Thanks
Printable View
What is the easiest way to convert the text in a text box to upper case as you are typing the letters?
Thanks
You would have to use javascript to do that by capturing the keypressdown event.
I believe there is no keypressdown event.
Code:<html>
<head>
<script language="javascript">
function MakeCaps(t)
{
var tmp;
tmp = t.value;
t.value = tmp.toUpperCase();
}
</script>
</head>
<body>
<form name=form1>
<input type=text name=txtUsername onkeyUp="javascript:MakeCaps(this);">
</form>
</body>
</html>
I meant just capturing the key events, such as key down, key up, key press, etc....Quote:
Originally posted by fmardani
I believe there is no keypressdown event.
Is there a way to do this using an asp control, rather than a html control?
Maybe somebody can help me with the following javascript:
The first if disables the enter button. I'm trying to use the same function to trap lowercase keystrokes, and convert them to upper case.Code:<script language=javascript>
function inspectEvent(evt){
if (evt.keyCode == 13)return false;
if (evt.keyCode > 96 && evt.keyCode < 123)return evt.keyCode - 32;
}</script>
For anybody interested:
Code:<HEAD>
<script language=javascript>function inspectEvent(evt){
if (evt.keyCode >= 97 && evt.keyCode <= 122)
{
Alpha=String.fromCharCode(evt.keyCode).toUpperCase();
evt.srcElement.value=evt.srcElement.value + Alpha;
return false;
}
else if (evt.keyCode == 13)return false;
}</script>
</HEAD>
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then Form1.Attributes.Add("onkeypress", "return inspectEvent(event)") End If End Sub