[ACCEPTED]-Convert lowercase letter to upper case in javascript-javascript

Accepted answer
Score: 26
<script type="text/javascript">
    function ChangeCase(elem)
        elem.value = elem.value.toUpperCase();
<input onblur="ChangeCase(this);" type="text" id="txt1" />

separate javascript from your HTML

window.onload = function(){
        var textBx = document.getElementById ( "txt1" );

        textBx.onblur = function() {
            this.value = this.value.toUpperCase();

<asp:TextBox ID="txt1" runat="server"></asp:TextBox>

If the 2 textbox is inside a naming container then 1 use something like this

var textBx = document.getElementById ("<%= txt1.ClientID %>");

            textBx.onblur = function() {
                this.value = this.value.toUpperCase();
Score: 17

Have you tried .toUpperCase()?



Score: 4

If you don't want to make an explicit JavaScript 2 function, here you can do it in just one 1 line:

Convert to lower and upper case respectively:

<asp:TextBox ID="txt1" onblur='this.value = this.value.toLowerCase();'></asp:TextBox>
<asp:TextBox ID="txt1" onblur='this.value = this.value.toUpperCase();'></asp:TextBox>
Score: 3

You can simply use CSS and do text-transform:uppercase and on submit 2 you run toUppercase(). Or you just submit as mixed and 1 you capitalize letters on server side :)

Score: 0

I would say the easiest way is..

<input id="yourid" style="**text-transform: uppercase**" type="text" />


Score: 0

Have you tried this?

var myString = "this is a String";
alert(myString.toUpperCase()); // "THIS IS A STRING"
alert(myString.toLowerCase()); // "this is a string"

Thanks... Hope you like 1 it.

More Related questions