You have to wrap your code with
$(document).ready(function(){
Thus, it will only work when the browser completes processing the structure of your HTML.
UPDATE
There was a lot of debugging material in your code, try this (it requires Firebug to see the result of the ajax request):
<script> $(document).ready(function(){ $("select[name='sweets']").change(function () { jQuery.ajax({ type: "POST", data: $("form#a").serialize(), success: function(data) { </script>
bfavaretto
source share