jquery - Set invalid input to initial value -


i have input on change send value via ajax , saved db. need prevent sending empty value or value not numeric , should or vice versa. calling ajax function after few if/else blocks. works ok, possible set invalid changed input previous value? example have input value "456321". user change "abcde". not numeric isn't send server need change value "456321".

keep hidden field filled initial value. suppose have value "4321" shown in text box. load value textbox in hidden field. on change of value when making ajax request, if value correct update hidden field correct value else replace value in textbox value in hidden field. hope helps...

sample code:

<input type="text" id="textbox" value="1234"/> <input type="hidden" id="hidden" value="1234"/>  $('#textbox').change(function(){     if(parseint($('#textbox').val()))        {            $('#hidden').val($('#textbox').val());            //make ajax request        }        else        {            $('#textbox').val($('#hidden').val());        } }); 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -