$(document).ready(function(){ $("#pollForm").submit(function() { var pid = $(this).children("input[@name='pid']").val(); var aid = $(this).children("input[@name='answer']:checked").val(); $("#pollForm").fadeOut("slow",function(){ $(this).empty(); $.getJSON("include/ajax/poll.php?aid="+aid+"&pid="+pid,loadPollResults); if (aid && aid != 'undefined') $.cookie('poll_id', pid, {expires: 365}); }); return false; }); if ($.cookie('poll_id') && $.cookie('poll_id') == 6) { $("#pollForm").empty(); $.getJSON("include/ajax/poll.php?pid="+$.cookie('poll_id'),loadPollResults); } }); function loadPollResults (data) { var total_votes = 0; var percent; for (id in data) { total_votes = total_votes+parseInt(data[id][2]); } var results_html = "
\n"; for (id in data) { percent = Math.round((parseInt(data[id][2])/parseInt(total_votes))*100); results_html = results_html+""+data[id][1]+" ("+data[id][2]+" votes)
 
"+percent+"%
\n"; } results_html = results_html+"

Total Votes: "+total_votes+"

\n"; $("#poll-container").append(results_html).fadeIn("slow",function(){ $("#poll-results div").each(function(){ var percentage = $(this).next().text(); $(this).css({width: "0%"}).animate({width: percentage}, 'slow'); }); }); }