Hi
I am having issues with a function that I created, I execute the below function on load on another page.
I would like it to enable all the inputs if a check box is selected or disable all inputes if it is not.
This works but it only works wih the first checkbox, so it's as if the code does not hit the next If Statement, If I move the Dep2 If statement above one then 2 it works an all others dont
//This function is used on the loading of the page so that if any of the dependant check boxes are ticked that the forms stay enabled
function autoenabledisableinput()
{
document.getElementById("DepID").style.display= 'none'; //hide div element on load
if(document.getElementById('Dep1').checked)
{
document.getElementById("DepID").style.display = ''; //show element when clicked
document.getElementById('Dep1Name').disabled = false;
document.getElementById('Dep1Surname').disabled = false;
document.getElementById('Dep1IDNumber').disabled = false;
document.getElementById('Dep1DOB').disabled = false;
document.getElementById('Dep1Passport').disabled = false;
}
if(document.getElementById('Dep2').checked)
{
document.getElementById("DepID").style.display = ''; //show element when clicked
document.getElementById('Dep2Name').disabled = false;
document.getElementById('Dep2Surname').disabled = false;
document.getElementById('Dep2IDNumber').disabled = false;
document.getElementById('Dep2DOB').disabled = false;
document.getElementById('Dep2Passport').disabled = false;
}
if(document.getElementById('Dep3').checked)
{
document.getElementById("DepID").style.display = ''; //show element when clicked
document.getElementById('Dep3Name').disabled = false;
document.getElementById('Dep3Surname').disabled = false;
document.getElementById('Dep3IDNumber').disabled = false;
document.getElementById('Dep3DOB').disabled = false;
document.getElementById('Dep3Passport').disabled = false;
}
if(document.getElementById('Dep4').checked)
{
document.getElementById("DepID").style.display = ''; //show element when clicked
document.getElementById('Dep4Name').disabled = false;
document.getElementById('Dep4Surname').disabled = false;
document.getElementById('Dep4IDNumber').disabled = false;
document.getElementById('Dep4DOB').disabled = false;
document.getElementById('Dep4Passport').disabled = false;
}
if(document.getElementById('Dep5').checked)
{
document.getElementById("DepID").style.display = ''; //show element when clicked
document.getElementById('Dep5Name').disabled = false;
document.getElementById('Dep5Surname').disabled = false;
document.getElementById('Dep5IDNumber').disabled = false;
document.getElementById('Dep5DOB').disabled = false;
document.getElementById('Dep5Passport').disabled = false;
}
if(document.getElementById('Dep6').checked)
{
document.getElementById("DepID").style.display = ''; //show element when clicked
document.getElementById('Dep6Name').disabled = false;
document.getElementById('Dep6Surname').disabled = false;
document.getElementById('Dep6IDNumber').disabled = false;
document.getElementById('Dep6DOB').disabled = false;
document.getElementById('Dep6Passport').disabled = false;
}
}
I would appreciate the assistance