A few things that might help you:
Don't use names like parent and child. You could get in trouble with reserved names.
You don't really need PHP to do this. You could do it all with JS. Take a look at the checkbox methods on a JS doc and you'll see.
Instead of this:
document.forms[0].elements['parent
[num]'].checked=true; // won't work
I'd do it like this:
document.forms[0].elements[n].checked = true // where 'n' is the number of the element
- If you're generating this JS piece with PHP, this will solve your problem: concatenation
Do it like this:
<?php
echo "document.forms[".$form."].elements[".$element_id."].checked = true;";
?>
Just watchout for the '.' and '"' from each language. Be careful so you don't get lost. In a bigger code that's easy to happen. Use a color syntax editor so you know where each one belongs.
Best regards,
Tim wrote:
Ok, I've read the pages that say --
Note that if you are using JavaScript the [] on the element name might cause you problems when you try to refer to the element by name. Use it's numerical form element id instead, or enclose the variable name in single quotes and use that as the index to the elements array, for example:
variable = documents.forms[0].elements['var[]'];
But I still can't get it to work. Here's the situation...
I've got a set of checkbox parent[] array and for each of those I've got a checkbox child[] array(s). If an element in the child[] array is chosen, then the parent[] for that child is/should be automatically chosen as well.
<SCRIPT Language="JavaScript">
function check_parent(num) {
document.forms[0].elements['parent[num]'].checked=true; // won't work
}
</SCRIPT>
while (db parent) {
echo "<input type=checkbox name=parent[]>";
while (db child) {
echo "<input type=checkbox name=child[] onclick=\"if (this.checked)....