javascript - Get input variable after it is filled then do ajax -


I have a checkout form where a zipcode is required. I need this zipcode to get a location ID, the zipcode is in 0000XX format but I need 4 digits first. Now I have created a space (global) javascript so that the locationID trough ajax is possible.

The only problem is that IM is now used when using a keyboard function, when a person types in a zipcode. But I want to activate it when a user has typed in something and clicks on another field. How can I do this?

  $ ('#deliveryzip'). Get bind ('funnel change', function () {// zip er zip = $ ('#department ZIP') Val (); // Strip 4 characters before input / check that 4 characters are integers / if all is ok If so ... // zipcode $ .post (jssitebaseUrl + '/ ajaxfile.php', {"zip": zip, "action": "getLocInfo"}, function (feedback) {if (response == "OK ("Show") {warning (response); // if the return is okay. Var show = true;}}); if (show) {$ ('# locInfo'). Show ();} and {$ ('# LocInfo '). Hide ();} Return false;});  

Instead of listening to the keyboard event, why do not you just hear the event change?

$ ('#deliveryzip'). On ('change', function () {....});

When an input field changes and loses the focus once, then a change event (like clicking through another element) gets burnt. More info (from Microsoft) and see the document from Mozilla here


Comments