request data on upc and throw it in an alert on hitting enter in the text field
authorOwen Smith <owen@omsmith.ca>
Mon, 19 Nov 2012 01:17:35 +0000 (20:17 -0500)
committerOwen Smith <owen@omsmith.ca>
Mon, 19 Nov 2012 01:17:35 +0000 (20:17 -0500)
www/assets/js/ui.js [new file with mode: 0644]
www/index.html

diff --git a/www/assets/js/ui.js b/www/assets/js/ui.js
new file mode 100644 (file)
index 0000000..628acb0
--- /dev/null
@@ -0,0 +1,18 @@
+$('input[name=upc]').keypress(function (e) {
+       var keyCode = e.keyCode || e.which;
+
+       if (keyCode === 13) {// enter
+               var input = $(this);
+
+               request_upc_data(input.val(), function (data) {
+                       alert(data.name);
+               });
+
+               input.val('');
+       }
+});
+
+function request_upc_data (upc, callback) {
+       $.ajax( 'upc.php?upc=' + upc )
+               .done(function (data) { callback(JSON.parse(data)); });
+}
index e36c5fe..f97cbb3 100644 (file)
@@ -28,7 +28,7 @@
                <footer id="footer">
                        <div class="container">
 
-                               <p>Sticky footer</p>
+                               <input type="text" name="upc" maxlength="12" placeholder="UPC-A" title="UPC-A" tabindex="0" />
 
                        </div> <!-- /container -->
                </footer>
@@ -39,6 +39,7 @@
                <script src="assets/js/pos_types.js"></script>
                <script src="assets/js/Pos.js"></script>
                <script src="assets/js/client.js"></script>
+               <script src="assets/js/ui.js"></script>
 
        </body>
 </html>