haripds
haripds

Reputation: 109

jquery key press event

I have text input box for quantity input. The input quantity is validated by key press event. when input quantity is greater than database's stored value then it shows alert popup message. It is working fine when we input number but the problem is that when we input number in textbox continuously greater than available stored data. it gives alert popup message more than once as many times key is pressed. i need to stop simultaneous key press and check for every input number. but the key press event doesn't support it.Do any one have faced such problem. How to limit the key press event or validate each key press?

Upvotes: 2

Views: 687

Answers (1)

Yes Barry
Yes Barry

Reputation: 9846

You could just delete the value that's in the textbox or subtract it after the first alert message.

var alertCount = 0; // make sure this is in global scope
var allowedAlerts = 1;

// ...

// within the keyup event listener
if (this.value > someNumber) {
    if (alertCount < allowedAlerts) {
        alert('Your error message');
        alertCount++;
    } else {
        this.value = ''; // or you could do the subtraction here
    }
}

Upvotes: 0

Related Questions