I have some code that works great... see below.
This works for one field on screen, I also need to load the function for multiple fields
eg.
ShowOrHide ('field1', 'field2', 'Value');
ShowOrHide ('field3', 'field2', 'Value');
ShowOrHide ('field4', 'field2', 'Value');
Here is the working code
<script>
window.attachEvent ('onload', function () {
ShowOrHide ('field1', 'field2', 'Value');
// Usage: ShowOrHide (field to hide, field to monitor, hide if value selected)
});
function ShowOrHide (a, b, c)
{
var hideElem=document.getElementById("_Data"+a);
var tElem=document.getElementById("_Data"+b);
if (tElem.childNodes[0].value!=undefined)
{
tElem.childNodes[0].onchange=Function("ShowOrHide('"+a+"','"+b+"','"+c+"')");
if (tElem.childNodes[0].value==c) hideElem.parentNode.style.display="none";
else hideElem.parentNode.style.display="";
}
else if ((tElem.innerText.replace(/ +$/,'')==c)) hideElem.parentNode.style.display="none";
}
</script>
I am aware that it can be used multiple times in the same onload function, but where do I add these?
Thanks
This works for one field on screen, I also need to load the function for multiple fields
eg.
ShowOrHide ('field1', 'field2', 'Value');
ShowOrHide ('field3', 'field2', 'Value');
ShowOrHide ('field4', 'field2', 'Value');
Here is the working code
<script>
window.attachEvent ('onload', function () {
ShowOrHide ('field1', 'field2', 'Value');
// Usage: ShowOrHide (field to hide, field to monitor, hide if value selected)
});
function ShowOrHide (a, b, c)
{
var hideElem=document.getElementById("_Data"+a);
var tElem=document.getElementById("_Data"+b);
if (tElem.childNodes[0].value!=undefined)
{
tElem.childNodes[0].onchange=Function("ShowOrHide('"+a+"','"+b+"','"+c+"')");
if (tElem.childNodes[0].value==c) hideElem.parentNode.style.display="none";
else hideElem.parentNode.style.display="";
}
else if ((tElem.innerText.replace(/ +$/,'')==c)) hideElem.parentNode.style.display="none";
}
</script>
I am aware that it can be used multiple times in the same onload function, but where do I add these?
Thanks