Skip to content Skip to sidebar Skip to footer

Convert Small To Capital On Keypressevent Using Javascript

How to convert capital latter when type small latter when fired onkeypress event? My Function is working in Internet Explorer but not working in Google Chrome and FireFox. function

Solution 1:

This doesn't need JS at all, just set text-transform: uppercase; for your element.

Solution 2:

Easy enough. Pass the element to your function and convert .

<scripttype="text/javascript">functionconvertCase(elem)
    {
        elem.value = elem.value.toUpperCase();
    }
</script><inputonkeypress="convertCase(this);"type="text"id="txt1" />

Solution 3:

document.getElementById('my-ok').onkeypress = function() {
  var self = thissetTimeout(function() {
    self.value = self.value.toUpperCase()
  }, 0)
}
<inputid='my-ok'type="text">

Event and timing

Solution 4:

Instead of writing script on keypress i suggest to write it on blur event like below.

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

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

Post a Comment for "Convert Small To Capital On Keypressevent Using Javascript"