0

I am trying to build a functionality where a user types text in the textbox and after a delay of 1 second, each character typed is converted to its upper case. This should happen as the user types.

Can i do using jquery?

2 Answers2

0

This might not be the most jQuery-esque way to do it, but something like this.

setInterval((function (textbox) {
    return function () {
        textbox.val(textbox.val().toUpperCase());
    }
}($("#myTextBox"))), 1000);

Of course changing $("#myTextBox") to the relevant selector

Brenton Alker
  • 8,947
  • 3
  • 36
  • 37
0

Check out the answer to this question for more detail:

How to delay the .keyup() handler until the user stops typing?

But here is a full working example of it all tied together:

$(document).ready(
    function()
    {
        var delay = (function(){
          var timer = 0;
          return function(callback, ms){
            clearTimeout (timer);
            timer = setTimeout(callback, ms);
          };
        })();

       $("#testerText").keyup(
           function()
           {
                delay(function()
                {
                    $("#testerText").val($("#testerText").val().toUpperCase());
                }, 1000);
           });
    });

http://jsfiddle.net/5Nq2f/

Community
  • 1
  • 1
spinon
  • 10,760
  • 5
  • 41
  • 59