All pastes #804032 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-12-03 01:21 UTC
rendered paste body
<?php
	if (!empty($_POST['pcode']))
	{
		$codes = $_POST['pcode'];

		$inventory = array_count_values($codes);
		arsort($inventory, SORT_ASC);

		foreach ($inventory as $code => $amount)
		{
			if (!empty($code))
				echo $code .' - '. $amount .'<br />';
		}
	
		die();
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
	"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
	<head>
		<title>Inventory Counter</title>
		<script type="text/javascript" src="jquery.js"></script>
		<script>
$(document).ready(function(){
	idnum = 0;
	formsubmit = false;

	$('#pcode').keyup(function(){
		if (document.getElementById('pcode').value.length == 6)
		{
			idnum = idnum+1;
			$('div#inputs').append('<input type="text" name="pcode[]" id="pcode'+idnum+'" maxlength="6" style="width: 50px" /><br />');
			document.getElementById('pcode'+idnum).value = document.getElementById('pcode').value;
			document.getElementById('pcode').value = '';
		}
		return false;
	});

	$('form#pcodes').submit(function(){
		return false;
	});

	$('#submit').click(function(){
		jQuery.post('index.php', $('form#pcodes').serialize(), function(data, textStatus){
		
			$('body').html(data);
		
		});
	});
			

});
		</script>
	</head>
	<body>
		<form id="pcodes" action="index.php" method="post">
			<div id="inputs"></div>
				<input type="text" name="pcode[]" id="pcode" maxlength="6" style="width: 50px" /><br />
			<input type="button" id="submit" value="Count Inventory" />
		</form>
	</body>
</html>