Search code examples
javascripthtmlfunctioninputonchange

Onchange event not triggering when using the minus sign


I'm experiencing a weird issue, or maybe it's something that i simply don't know

i am using an input type text to capture and update a value using ajax.

<input type="text" onchange="functionx(this);" style="width:80px; margin-top: 5px;" name="stock" id="stock" />

if i put any alphanumeric value on the field the javascript function get fired correctly, even if i put the plus sign and some numbers (+123456) but if i use the minus sign it doesn't work (-123456) what am i missing or doing wrong?

Thanks in advance.

UPDATE

function functionx(obj){
  alert("function is being called");
}

Solution

  • Validate in your JS that you are comparing with a NULL or undefined value and not with a value who is bigger than 0, i tested this on jsFiddle and its working fine.

    Something in your validation could be causing this issue.

    function functionx(obj){
     var objval = obj.value;
      if(objval != ""){
         alert(objval);
      }  
    }
    

    Check this fiddle