Home > Javascript > Make Text in TextBox to Upper Case

Make Text in TextBox to Upper Case


Hi

try these examples:

STEP# 1:

Add following in your Page_Load event block:

this.TextBox1.Attributes.Add("onBlur", "javascript:ConvertCase(this);");

STEP# 2:

Add following javascript function your html code of design page, in <Head../> block:

<script language ="javascript" >
   function ConvertCase(objTextBox)
   {
       objTextBox.value = objTextBox.value.toUpperCase();
   }
</script>

//—— or

function isTabKey(event)
{
///<summary>Checks whether the tab key has been pressed.</summary>
///<param name="event" type="Object" optional="false">(Required). The event Object.</param>
///<returns type="Boolean" />   
if (event)
{       
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;       
return keyCode == 9;   
}
}
function Blured(event)
{   
if(isTabKey(event))
{       
return true;   
}
}

<input type="text" onblur="var mytxt=this.value; this.value=mytxt.toUpperCase();" onkeydown="Blured(event);" />

//——- or

<script language="javascript" type="text/javascript" >
   function toUppercase(obj)
    {
      var lower=obj.value;
      var upper=lower.toUpperCase();
      obj.value=upper;
     }
</script>
<form>
  <asp:TextBox ID="TextBox1" runat="server" onblur="javascript:toUppercase(this);" ></asp:TextBox>
</form>

Good Luck

Advertisements
Categories: Javascript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: