I am fairly new to jquery and I am working with jsp and struts .as part of the application I have a survey form with a number of categories each with different set of questions, and each question with a number of possible answers to pick from as radio buttons. I want the user to be required to pick one answer for each question in each category before submitting the form and to give an error if they don't.
<s:iterator value="quelists">
<tr class="radioList">
<td>
<s:property value="surveyQuestion"/><span id="msg_selectError"/>
</td>
<td >
<s:iterator value="answerslists" status="status">
<s:radio value="selectedAnswers[%{#count}]"
name="selectedAnswers[%{#count}]"
list="#{id:answer}" required="true" theme="simple"/>
</s:iterator>
</td>
<s:set var="count" value="#count+1"/>
</tr>
</s:iterator>
I am just learning.. It work: http://jsfiddle.net/WDfXq/2/
function isCheck() {
var isOk = true;
$('.radioList').each(function(){
var countChecked = $(this).find(':checked').length;
if(countChecked!=1) {
$(this).css('color', 'red');
isOk = false;
} else {
$(this).css('color', 'black');
}
});
return isOk;
}