0

I have a simple HTML like this:

Get alert with inserting a + sign: <input type="text" class="data" />

I want alert user whenever he/she press + key. But my jQuery code does not work:

$(document).ready(function(){
    $(".data").bind('keydown',function(e){
        if(e.which == 107){
            alert('Plus sign entered');
        });
    });
});

What do I have to do ?

(This is my jsFiddle)

Mohammad Saberi
  • 12,274
  • 25
  • 67
  • 125

1 Answers1

1

There were two things wrong in this code.

  1. There was a typo(?) - closing curly braces for the IF condition
  2. The key ID for SHIFT and = (which is +) is different from the numpad +

The following code fixes it

$(document).ready(function(){
    $(".data").bind('keydown',function(e){

        if(e.which == 107 || e.which == 187){
            alert('Plus sign entered');
        }
    });
});

Here's the fiddle - http://jsfiddle.net/DgUUB/

JohnP
  • 48,581
  • 13
  • 106
  • 137