2

I am calling .keyup function of Search Textbox, and in that keyup(), I am refreshing the GRID from the database.

Problem:

But the grid is getting refreshed for (special keys too ) arrow keys, number lock,function keys and all other keys and refreshing for those keys are unnecessary. Except backspace, return,tab,space,delete.

I want to construct a regular expression such that it filters out all the control keys.

Sample code:

$('#searchContent').keyup(function (e) {
    var key = e.which;
    if ( /*condition*/ ) {
        return;
    }
    //my code goes here...
}

What I have done:

Searched net thoroughly and I came up with hotkey, but that doesn't solved my purpose. So, any smart regular expression are there?

shytikov
  • 9,155
  • 8
  • 56
  • 103
Muthu Ganapathy Nathan
  • 3,199
  • 16
  • 47
  • 77

2 Answers2

0

Try this HTML to see which codes match up with which keys (taken from Mozilla):

<html>
<head>
    <title>charCode example</title>

    <script type="text/javascript">

        function showChar(e)
        {
            alert("Key Pressed: " + String.fromCharCode(e.charCode) + "\n"
                  + "charCode: " + e.charCode);
        }

        </script>
    </head>

    <body onkeypress="showChar(event);">
        <p>Press any 'character' type key.</p>
    </body>
</html>
rhughes
  • 9,257
  • 11
  • 59
  • 87
0

Try this trick:

function checkForChanges(){
   var txt = $('#searchContent');
   if(txt.val() != txt.attr('xvalue') {
      //do referesh grid content here
   }
}

$('#searchContent').keyup(function (e) {
    $(this).attr('xvalue') = this.value;    
    clearTimeout(this.changeTimer);    
    this.changeTimer = setTimeout(checkForChanges, 20);
}
jerjer
  • 8,694
  • 30
  • 36