I have a html form, which has lots of checkboxes, and there is a Select All box on top, how to make the Select All box auto select all the checkboxes below according to the Select All box choice ?
I didn't want to show the code, because it's nasty looking, I'm debugging an old app, but since you asked, here it is :
<script language="javascript">
function selectAll2(value) {
var elem = document.forms[1].getElementsByTagName("select");
var count = ${questionCount};
for(var i = 1; i <= count; i++) {
if(i != 23 || (i==23 && ${w.carrier.stateOfDomicile ne 'FL'})) {
elem[i].value = value;
showNoShowQuestionaire(i,'Y','N',value);
}
}
}
</script>
<!-- Question # ${n} -->
<tr>
<td class="${labelClass}" align="right" valign="top" width=26%>
${n}.
</td>
<td class="${labelClass}" align="left">
${q}
</td>
<c:choose>
<c:when test="${not_applicable eq 'Y'}">
<td valign="top">
<div id="QT_${n}">
<html:select disabled="${disabled}" property="answers" styleClass="display: none;" value="${s}">
<html:option value="Y">Yes</html:option>
</html:select>
</div>
<script language="javascript">
document.getElementById("QT_${n}").style.display = 'none';
</script>
</td>
</c:when>
<c:otherwise>
<td valign="top">
<html:select disabled="${disabled}" property="answers" styleClass="processSelect" value="${s}" onchange="showNoShowQuestionaire('${n}','${yes_exp}','${no_exp}',this.value);">
<html:option value="">--</html:option>
<html:option value="N">No</html:option>
<html:option value="Y">Yes</html:option>
</html:select>
</td>
</c:otherwise>
</c:choose>
</tr>
From the above code, I got an error message for firefox and Chrome, it says : elem[i] undefined. It works fine in IE.
Since my app needs to work in all browsers, is there a solution that works for all browsers ?