Skip to content

Instantly share code, notes, and snippets.

@cgsmith
Created December 4, 2013 18:23
Show Gist options
  • Save cgsmith/7792758 to your computer and use it in GitHub Desktop.
Save cgsmith/7792758 to your computer and use it in GitHub Desktop.
<input id="qty" type="text" value="" name="qty[]">
<input id="upc" type="text" value="" name="upc[]" disabled>
<input id="name" type="text" value="" name="name[]" disabled>
<input id="price" type="text" value="" name="price[]" disabled>
<input id="extprice" type="text" value="" name="extprice[]" disabled>
<br/>
<?php
//Just an example, not production
$product = array('upc'=>'1234','price'=>1,'name'=>'Internets');
echo json_encode($product);
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
function getProduct(str) {
$.ajax({
url: 'sale/add.php',
data: 'query='+str,
dataType: 'json',
success: function(data) {
$('.upc').val('');
$('#cart').append(
$('<div />').load('views/sale/_addItem.php',function(){
$('#qty').val('1');
$('#upc').val(data['upc']);
$('#name').val(data['name']);
$('#price').val(data['price']);
})
);//"Name: " + data['name']);
return false;
},
error: function() {
$('.upc').val('');
alert('No product found!');
}
});
}
$( ".sale-add-button" ).click(function() {
getProduct($('.upc').val());
});
$('.upc').bind("enterKey",function(e){
getProduct($('.upc').val());
});
$('.upc').keyup(function(e){
if(e.keyCode == 13){
$(this).trigger("enterKey");
}
});
});
</script>
<h1>Point of sale</h1>
<input type="text" class="upc input-medium" placeholder="UPC" name="upc" autocomplete="off" >
<button type="submit" class="sale-add-button btn">Add to Cart</button>
<form class="form-inline" method="POST" action="index.php?action=sale/add">
<div id="cart">
</div>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment