Forum Moderators: open
I have a small on a php-generated page, which ticks a set of checkboxes on the press of a button. The problem is that the checkbox names are generated from the database.
Until I had to change the field names, the following worked:
onClick="checkAll(document.form1.Teignbridge)" Can I use a wildcard in order to tell it to click all fields that begin with "Teignbridge"?
This should help you out, by adding [checkbox1] to your static input tags name after your variable, then calling on the function.
<script language="javascript">
function selectUnselectAll(grp, button) {
var form, el, e, f = 0;
var unbuttoned = (button.value.substring(0,2).toLowerCase() == 'un');
while (form = document.forms[f++]) {
e = 0;
while (el = form.elements[e++])
if (el.type == 'checkbox' && el.name.indexOf(grp)!= -1) el.checked =!unbuttoned;
}
button.value = unbuttoned? button.value.substring(2) : 'un' + button.value;
}
</script>
<input type="checkbox" name="Teignbridge1[checkbox1]">Teignbridge1<br>
<input type="checkbox" name="Teignbridge2[checkbox1]">Teignbridge2<br>
<input type="checkbox" name="Teignbridge3[checkbox1]">Teignbridge3<br>
<input type="checkbox" name="Teignbridge4[checkbox1]">Teignbridge4<br><br>
<input type="checkbox" onclick="selectUnselectAll('checkbox1',this)">Type1
HTH,
-George