-1

I am working with HTML and JQuery. Now I am trying onkeyup in HTML. But It doesn't worked. HTML:

 <p>A function is triggered when the user releases a key in the input field. The function transforms the character to upper case.</p>

Enter your name:

JS;

function myFunction() {
var x = document.getElementById("fname");
x.value = x.value.toUpperCase();
}

fiddle:http://jsfiddle.net/qsxccd36/

jack rose
  • 97
  • 11

2 Answers2

0

Try with -

<input type="text" id="fname">

Use jquery -

$(document).ready(function() {
    $('#fname').on('keyup', function() {
        $(this).val($(this).val().toUpperCase());
    })
})
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
0

Use input event instead of keyup

Occurs when the text content of an element is changed through the user interface.

$('#fname').on('input', function() {
        $(this).val($(this).val().toUpperCase());
});

Fiddle

Sudharsan S
  • 15,336
  • 3
  • 31
  • 49