I have this code which basically if you uncheck the parent checkbox and if any of the other checkboxes are checked, they will also uncheck.

<script type="text/javascript">

function c_uncheck()
{


var field1 = document.myform.lista;
var field2 = document.myform.listb;
var field3 = document.myform.listc;
var field4 = document.myform.listd;

for (a = 0; a < field1.length; a++)
{
if(!document.myform.Parentlist.checked)
{

for (b = 0; b < field2.length; b++)
{

field2[b].checked = false;

}

for (d = 0; d < field3.length; d++)
{

field3[d].checked = false;

}

for (e = 0; e < field4.length; e++)
{

field4[e].checked = false;

}

field1[a].checked = false;

}
}
}

</script>

<form action="test_check.php" method="post" name="myform">
<input type="checkbox" onclick="c_uncheck();" ID="Parentlist" name="Parentlist" value="1">Parent<br>
<input type="checkbox" ID="lista" name="list" value="2">Child 1<br>
<input type="checkbox" ID="lista" name="list" value="3">Child 2<br>
<input type="checkbox" ID="lista" name="list" value="4">Child 3<br>
<input type="checkbox" ID="lista" name="list" value="5">Child 4<br>
<input type="checkbox" ID="listb" name="listb" value="4">b 1<br>
<input type="checkbox" ID="listb" name="listb" value="5">b 2<br>
<input type="checkbox" ID="listc" name="listc" value="4">c 1<br>
<input type="checkbox" ID="listc" name="listc" value="5">c 2<br>
<input type="checkbox" ID="listd" name="listc" value="3">d 1<br>
<input type="checkbox" ID="listd" name="listc" value="5">d 2<br>


<input type="submit" name="submit" value="submit"/></form>

This works exaclty how i want it to except....

I would like to dynamically call different input fields,
so something like this:

<input type="checkbox" onclick="c_uncheck('lista', 'listb', 'listc');" ID="Parentlist" name="Parentlist" value="1">Parent<br>

But i don't know how to get the javascript to work with what i already have.

Currently I have:

var field1 = document.myform.lista;

I would like to have it be something like:

var field1 = document.myform.inputfieldname;

Where inputfieldname would be any input field i want to name.

Hopefully that makes sense. Any help would be greatly appreciated!
thanks

PS: I am a js beginner, so i will probably need things explained very clearly as I suck at this.

If you want to have something like that then the javascript code must cater for it, so if you are going to send in three variables then the function must have three parameters, so the js function will look something like this:

function c_uncheck(var1, var2, var3){
...
}

lets say you called your function like this:

onclick="c_uncheck('inputfieldname', 'inputfieldname1', 'inputfieldname2')"

then in the function to refer to inputfieldname you would do this

var field1 = document.myform.var1;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.