Friday, June 14, 2013

How to convert textbox value to Uppercase Or Lowercase in Asp.net using JavaScript

Introduction: In this I will explain how we can change the text to Uppercase or Lowercase using JavaScript in Asp.net.
Uppercase Or Lowercase

Description:
Put the below given JavaScript between Head tag of webform:
For Uppercase:

<script type="text/javascript">
        function Uppercase(id) {
            var txt = document.getElementById(id);
            txt.value = txt.value.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
        }
    </script>

For Lowercase:

<script type="text/javascript">
        function Lowercase(id) {
            document.getElementById(id).value = document.getElementById(id).value.toLowerCase();
        }
    </script>

After that drag and drop the Textbox control from Toolbox and onkeyup call the JavaScript function. As shown below:

  <table border="1px dotted">
    <tr><td><b>Uppercase Example</b></td></tr>
    <tr><td>First Name:</td><td>
        <asp:TextBox ID="txtuppercase" runat="server" onkeyup="Uppercase(this.id)"></asp:TextBox></td></tr>
        <tr><td><b>Lowercase Example</b></td></tr>
        <tr><td>First Name:</td><td><asp:TextBox ID="txtlowercase" runat="server" onkeyup="Lowercase(this.id)"></asp:TextBox></td></tr>
    </table>


Now run the project and check the result.

Is it helpful?

If yes post your comment to admire my work. You can like me on Facebook, Google+, Linkedin and Twitter via hit on Follow us Button and also can get update follow by Email.

2 comments:

  1. Howdy! I know this is somewhat off-topic however I had to
    ask. Does managing a well-established website such as yours require a
    lot of work? I am brand new to operating a blog however I do write in my diary daily.

    I'd like to start a blog so I can share my experience and feelings online.
    Please let me know if you have any kind of recommendations or tips for new aspiring blog owners.
    Thankyou!

    Feel free to surf to my web-site; Fine Dining Blog (http://www.twerksessions.com/members/paulimilson/activity/11946/)

    ReplyDelete
  2. Oh my goodness! Awesome article dude! Many thanks, However I am encountering issues with your RSS.
    I don't understand why I can't subscribe to it.
    Is there anybody else getting similar RSS issues? Anyone that knows the solution can you
    kindly respond? Thanks!!

    My blog ... seo

    ReplyDelete