Jump to content

Help changing hiddden field


cs1h

Recommended Posts

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,

<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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.