put it around $('.quantity, .drink').change(calculateTotal);
The function declaration does not need to be in the onReady block, in fact it makes sense to move it outside of it (you want to expose the function for later use/use by other libraries). Just the implementation need be in the block. The only thing that needs to be in on-document-ready is stuff you want to run on the ready dom, like changing the total in your example.
Revised code
<script type="text/javascript">
// Shorthand for $( document ).ready()
$(function() {
$('.quantity, .drink').change(calculateTotal);
});
function calculateTotal() {
var $form = $(this).closest('form'), total = 0;
$form.find('.drink:checked').each(function() {
total += $(this).data('price') * parseInt($(this).next('.quantity').val() || 0, 10);
});
$('#totalDiv').text(total);
}
</script>
You could impart a degree of the meaning of private
by moving it into the anonymous onready function, if that were important to you. unless you really want to prevent other/later code from using your own, its nice to have it public like that.
On the other hand, you are polluting the public namespace with a function that some other library could later overwrite. If you had many functions the chances of collision go up. It is good practice to then use a namespace.