On 9/6/07, Shaun Kester <[EMAIL PROTECTED]> wrote: > > I figured out the missing ';', sorry about that. I found this function > in the archive and it works for alerting me that one of the radio sets > is not checked. Is there any way in the alert for it to tell me the > name, id, or rel attribute of the group that stopped the find? > > if(!$(this).find("[EMAIL PROTECTED]:checked").size()){ > alert( "All questions are required. Please check your > entries." ); > return false; > };
Ah yeah, the missing ; thing is because I used commas in the for initialisation instead of semi-colons, right? Anyway, as for your new code, I don't know what 'this' refers to so I will assume you want it to refer to a set of radio buttons. You will need to target all the sets somehow so add a class to the containing element of each set. Let's call it 'radioSet'. So your HTML will look like this: <tr class="zOdd radioSet"> <td>1. I am proud to be part of the [redacted].</td> <td nowrap="nowrap" valign="top"> <label for="p1q1-1">1</label><input value="1" id="p1q1-1" name="p1q1" type="radio"> <label for="p1q1-2">2</label><input value="2" id="p1q1-2" name="p1q1" type="radio"> ... </td> </tr> <tr class="zEven radioSet"> <td>2. I see myself working for the [redacted] three years from now.</td> <td nowrap="nowrap" valign="top"> <label for="p1q2-1">1</label><input value="1" id="p1q2-1" name="p1q2" type="radio"> <label for="p1q2-2">2</label><input value="2" id="p1q2-2" name="p1q2" type="radio"> ... </td> </tr> Then this jQuery code might work: function validate_form(){ var valid = true; //loop through the radio sets $('tr.radioSet').each(function(){ var theRadioSet = this; //make sure at least one radio is checked //do not use @ symbol if using jQuery 1.1.4, it's deprecated if ( $('input[type=radio]:checked',theRadioSet).length != -1 ){ valid = false; alert ('The question with id "'+theRadioSet.id+'" was not answered'); return false; //I *think* this halts further 'each' cycles } }); return valid; } Hope this gets you closer to where you want to be. Joel Birch.