I am trying to figure out a simple radio validation using a simple function. Basically there are 12 sets of radio buttons, 4 buttons in each set. Sets are names q1, q2, q3 ... q12. I want to loop through each set without having to write an independent function for each. My script works for a single function, but I get an error when I try to loop through each function. I want a corresponding error variable set for each set that is not checked, and this is what's causing the problem. Ex: if set q1 has not been pressed, I want error1 to = 1. For set 2, error2 = 1, etc. var total = 12; for (i = 1; i <= total; i++){ // set var radio_choice to false var radio_choice = false; for (counter = 0; counter < survey.q[i].length; counter++){ if (survey.q[i][counter].checked) radio_choice = true; } if (!radio_choice){ var error[i] = 1; } } Code (markup):