request data on upc and throw it in an alert on hitting enter in the text field
[omsmith/pos-js.git] / www / assets / js / ui.js
1 $('input[name=upc]').keypress(function (e) {
2         var keyCode = e.keyCode || e.which;
3
4         if (keyCode === 13) {// enter
5                 var input = $(this);
6
7                 request_upc_data(input.val(), function (data) {
8                         alert(data.name);
9                 });
10
11                 input.val('');
12         }
13 });
14
15 function request_upc_data (upc, callback) {
16         $.ajax( 'upc.php?upc=' + upc )
17                 .done(function (data) { callback(JSON.parse(data)); });
18 }