Lets say I have two hidden form field inputs:
<input id="val1" name="val1" value="0"/>
<input id="val2" name="val2" value="0"/>
Lets say I have a warning DIV with a message that I want to display if both of these inputs have a value of "1"
<div id="myWarningDiv" style="display: none;" class="clswhatever">
You have done something wrong comrade!
</div>
Now suppose there are many ways to trigger a change one or both of these hidden field values. What I don't want to do is change code on each of these triggers to check if both of these values are "1". Is there a way I can just add a custom event that would just listen for this to happen, without using setInterval or anything clugy like that?
This is a simple example. What I am really looking for is NOT a way to attach an event to a single DOM element, but to create a custom condition that might span mutiple DOM objects, but when triggered would call an event handler function. Heres some pseudo code:
public Boolean onBothTrue() {
if (document.getElementById("val1").value == "1" && document.getElementById("val2").value == "1") {
return true;
}
else {
return false;
}
}
document.addEventListener('onBothTrue',myEventHandler);
function myEventHandler() {
var elem = document.getElementById("myWarningDiv");
elem.style.display = "block";
}