I have a form with 10 multiple choice questions, the input for each option is a radio button.
Following a few guides and posts from this forum, on form submit I have been able to serialze the values from each selected radio butoon and show the values within a results div. So for example on submit the values "1 2 1 1 4 4 1 1 6 1" might be displayed.
What I'd like to do is just show the most commonly occuring value. (in the above example that would be 1.
Based on links supplied, I've worked out some of what I need to do but am now stuck again!
function showValues() {
var store = $( ":radio" ).serializeArray();
var frequency = {}; // array of frequency.
var max = 0; // holds the max frequency.
var result; // holds the max frequency element.
for(var v in store) {
frequency[store[v]]=(frequency[store[v]] || 0)+1; // increment frequency.
if(frequency[store[v]] > max) { // is this frequency > max so far ?
max = frequency[store[v]]; // update max.
result = store[v]; // update result.
}
}
alert(result);
}
returns "Object object" in the alert?
What have I missed?