Jquery result from sum of array incorrect -
var answ = []; $(document).ready(function() { $("#result").click(function() { answ = []; $('input[type="radio"]:checked').each(function(){ answ.push($(this).val()); //push values in array }); var total = 0; (var = 0; < answ.length; i++) { total += answ[i] << 0; } console.log(total); }); }); $("#shlong").click(function() { console.log(answ); }); fb.ui( { method: 'feed', name: 'facebook dialogs', link: 'http://developers.facebook.com/docs/reference/dialogs/', picture: 'http://fbrell.com/f8.jpg', caption: total, description: 'dialogs provide simple, consistent interface applications interface users.', message: 'facebook dialogs easy!' }, <input type="radio" name="quiz1" value="1"> <input type="radio" name="quiz2" value="4"> <input type="radio" name="quiz3" value="1"> <button id="result">penis</button> <input type="button" onclick="share_prompt()" value="share" />
hello all, trying have results code @ top ($total) display in fb.ui displays entire array like: ["1"], ["4"], ["1"] how make output console.log single number
instead of debbuging messy un-indented code, i'm gonna offer simpler approach. first, question asked myself , couldn't find answer..
why storing every value in array??
ok, it's out of system now.. let's avoid using useless array of yours , things done quickly..
my suggestion add each value total
while loop.. this:
$(document).ready(function () { $("#result").click(function () { var total = 0; $('input[type="radio"]:checked').each(function () { total += this.value << 0; }); alert(total); }); });
edit: in order have best answer, here working jsfiddle
Comments
Post a Comment