Click to See Complete Forum and Search --> : Checkboxes onchange issue with dynamically named checkboxes


kiazoe
12-12-2005, 08:01 AM
Hi all,

Problem: I have a cgi webpage which creates a list of checkboxes - they are a list of directories. These are named dynamically (by foldername/subfoldername/etc) I am looking to have the subfolders disable when the parent directory is clicked.

I have a very basic code at the minute just so i can test the functionality of the onchange, document.formname.checkboxname.disabled="true" and i know that this works.

Example, i have some a folder called 'English' and it has a subdirectory called English\Other (the \ is there because it is a directory structure, i know this causes problems but i'm not sure of the workaround, i have tried English\\Other but to no avail)

Error: illegal character
Source Code:
swap(this.form.Arabic\ACSAP.checked)

Above is an example of the error i recieve when trying to automatically disable a subfolder by name.

This is only the first part of my problem. Because the checkboxe names are not static I cannot state exactly what to disable. One thing which relates the checkboxes to their parent checkbox is the start of the name. I have looked at using GetEntityId and a regular expression to search for the current folder name + anything but am not sure how to go about even starting this (i'm an amateur at javascript)

It's quite difficult to explain but hopefully that makes sense to someone :) - i unfortunately can't link you to an example as the page is on an internal network.

Thanks in advance,
Eoin.

vwphillips
12-12-2005, 08:31 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--

function Disable(obj){
tbs=document.getElementsByTagName('INPUT');
for (zxc0=0;zxc0<tbs.length;zxc0++){
if (tbs[zxc0].name.match(obj.name)&&tbs[zxc0]!=obj){
if (obj.checked){
tbs[zxc0].setAttribute('disabled','disabled');
}
else {
tbs[zxc0].removeAttribute('disabled');
}
}

}
}
//-->
</script></head>

<body>
<input type="checkbox" name="English" onclick="Disable(this);">
<input type="checkbox" name="English\A">
<input type="checkbox" name="English\B">
<br>
<input type="checkbox" name="French" onclick="Disable(this);">
<input type="checkbox" name="French\A">
<input type="checkbox" name="French\B">

</body>

</html>

kiazoe
12-12-2005, 08:39 AM
wow thanks,

works to perfection. you're a star!

kiazoe
12-12-2005, 08:56 AM
could you perhaps comment the function if you get a chance? I'm just trying to understand how it works. I have commented a little of what i understand.

tbs=document.getElementsByTagName('INPUT');
// adds all input elements of the form to an array called tbs

for (zxc0=0;zxc0<tbs.length;zxc0++){
// go through each item in the array

if (tbs[zxc0].name.match(obj.name)&&tbs[zxc0]!=obj){
// if the array matches the value passed into the function and it is not the exact match (?) I assume this is a regexp search on the current string?

if (obj.checked){
// if the value passed in to the function is checked

tbs[zxc0].setAttribute('disabled','disabled');
// the current array value is set to disabled.
}
else { tbs[zxc0].removeAttribute('disabled');
// otherwise the value is unchecked and all subdirectories are also unchecked.


is there a reason for the strange variable namings or?

Thanks again