tags:

views:

284

answers:

2

hi friends,

i have a textbox and when i enter 0 in it, it should reset to 1 and display warning message.

i tried with blur() and change(), it is working but the problem is, it is displaying warning on coming out of focus from textbox after entering 0..

what i need is as soon as i enter 0 in textbox the warning msg should come

i have attached code what i tried

$("#textbox1").change(function(){
  textboxfunction();
  });

  function textboxfunction(){
    ($("#textbox1").val() == 0) ? $("#warning").show() && $("#textbox1").val(1) :   $("#warning").hide()
  }
+2  A: 

You need the keyup event instead, I think:

$("#textbox1").keyup(function(){
   textboxfunction();
});
Mark B
+1  A: 

As Mark B mentioned, you need to use keyup, but you also need to put the 0 in quotes:

$("#textbox1").val() == "0"

The string "0" is different than the number 0, especially when == is involved!

No Surprises