grabbing barcode reader
HTML
<ul id="codes">
<li>NICK</li>
<li>CLARKSON</li>
</ul>
JavaScript
// lock scopell
// init empty string to hold current code
var str = '';
// bind to key down event
$(window).keydown(function(e) {
// get character from keycode ( always uppercase )
var key = String.fromCharCode(e.keyCode);
// is current key enter?
if (e.keyCode == 13) {
// try and find code in current list and identify
if ($('#codes li:contains(' + str + ')').css({
'background': 'red'
}).length == 0) {
// if not in list append it
$('<li>' + str + '</li>').appendTo('#codes').css({
'background': 'green'
});
}
// empty string in preparation for net code
str = '';
} else {
// concat string until enter is pressed
str += key;
}
})
})();