Hi,
I am writing a script which contains several check boxes, one of which selects all of the other check boxes. When check boxes are ticked the information from their values is put into a hidden field as a list and if it is un-ticked it is removed. When the one which selects all of the other check boxes is ticked I want all there values to be added to the list.
I cannot get the script to fill in the hidden field when the all check box is selected.
The code is,
[CODE]
<html>
<head>
<title>untitled</title>
<script type=”text/javascript” language=”javascript”>
function display(box) {
// get reference to form object, and to array of same-named checkboxes
var temparr = new Array(), f = box.form, boxgroup = f[box.name];
// loop through it
for (var i=0; i<boxgroup.length; i++) {
// add the value of any checked box to next available slot in temparr
if (boxgroup[i].checked) temparr[temparr.length] = boxgroup[i].value;
// run the .join() method on the array (separator = ‘,’) and output it to field
f.readout.value = temparr.join(‘,’);
}
}
function Check(chk)
{
if(document.myform.Check_ctr.checked==true){
for (i = 0; i < chk.length; i++)
chk[i].checked = true ;
}else{
for (i = 0; i < chk.length; i++)
chk[i].checked = false ;
}
}
</script>
</head>
<body onLoad=”document.forms[0].reset()”>
<form name=”myform”>
<ul>
<li><label><input type=”checkbox” name=”Check_ctr” value=”yes” onClick=”Check(document.myform.group)”/></label> All Africa</li>
<li><label><input type=”checkbox” name=”group” value=”01A” onclick=”display(this)” onChange=”display(this)”/></label> Algeria</li><li><label><input type=”checkbox” name=”group” value=”02A” onclick=”display(this)” onChange=”display(this)”/></label> Angola</li><li><label><input type=”checkbox” name=”group” value=”03A” onclick=”display(this)” onChange=”display(this)”/></label> Benin</li><li><label><input type=”checkbox” name=”group” value=”04A” onclick=”display(this)” onChange=”display(this)”/></label> Botswana</li><li><label><input type=”checkbox” name=”group” value=”05A” onclick=”display(this)” onChange=”display(this)”/></label> Burkina_Faso</li><li><label><input type=”checkbox” name=”group” value=”06A” onclick=”display(this)” onChange=”display(this)”/></label> Burundi</li><li><label><input type=”checkbox” name=”group” value=”07A” onclick=”display(this)” onChange=”display(this)”/></label> Cameroon</li><li><label><input type=”checkbox” name=”group” value=”08A” onclick=”display(this)” onChange=”display(this)”/></label> Canary_Islands</li><li><label><input type=”checkbox” name=”group” value=”09A” onclick=”display(this)” onChange=”display(this)”/></label> Cape_Verde</li><li><label><input type=”checkbox” name=”group” value=”10A” onclick=”display(this)” onChange=”display(this)”/></label> Central_African_Republic</li><li><label><input type=”checkbox” name=”group” value=”11A” onclick=”display(this)” onChange=”display(this)”/></label> Chad</li><li><label><input type=”checkbox” name=”group” value=”12A” onclick=”display(this)” onChange=”display(this)”/></label> Comoros</li><li><label><input type=”checkbox” name=”group” value=”13A” onclick=”display(this)” onChange=”display(this)”/></label> Congo</li><li><label><input type=”checkbox” name=”group” value=”14A” onclick=”display(this)” onChange=”display(this)”/></label> Democratic_Republic_of_Congo</li><li><label><input type=”checkbox” name=”group” value=”15A” onclick=”display(this)” onChange=”display(this)”/></label> Djibouti</li>
</ul>
<br><input type=”hidden” name=”readout” size=”20″>
</form>
</body>
</html>
Can anyone help solve this?
Thanks,
Cs1h