danielbdavis
12-11-2010, 06:50 AM
In building a web page, I needed to learn about event listeners. I built a small testPage, consisting of 3 tables: an outer one containing 2 inner tables which appeared side-by-side. The effect targeted was rollover (or mouseover, as it is now called). I chose the simplest effect I could think of - background change, coded it, and it worked! Accordingly, I went on to my real desired effect: visibility. (Not display or non-display, but visible or not-visible.)
Accordingly, I duplicated the working code, but it did not work. The browser is Firefox 5.0, and the error pane shows nothing. It is mystifying. The only difference is that the visibility code that works has been used outside of an event listener. The relevant JavaScript code appears below.
The outer table is "outerTable" the inner table with the working color change is "rollTable", and the inner table with the non-working visibility is "optionsTable". Note that the visibility-switching statements have been independently tested elsewhere and they work just fine, as exemplified by the inititializing call to setvis on the 'optionsTable' to hide it at the start! Note further that the alerts for 'doshow' and 'dohide' never fire, nor is there an error indication.
<script type="text/javascript">
var dored;
var doblue;
var doshow;
var dohide;
function registerEventListeners() {
var rt = document.getElementById("rollTable");
var ot = document.getElementById("optionsTable");
alert("register");
rt.addEventListener("mouseover",setred,false);
rt.addEventListener("mouseout",setblue,false);
dored = function() { rt.bgColor = "red" };
doblue = function() { rt.bgColor = "blue" };
setvis("optionsTable",-1);
alert("optionsTable");
doshow = function() {
alert("doshow");
ot.style.visibility="visible";
}
dohide = function() {
alert("dohide");
ot.style.visibility="hidden";
}
ot.addEventListener("mouseover",setshow,false);
ot.addEventListener("mouseout",sethide,false);
}
function setred() { dored(); }
function setblue() { doblue(); }
function setshow() { alert("setshow"); doshow(); }
function sethide() { alert("sethide"); dohide(); }
</script>
Many thanks for any and all help.
Accordingly, I duplicated the working code, but it did not work. The browser is Firefox 5.0, and the error pane shows nothing. It is mystifying. The only difference is that the visibility code that works has been used outside of an event listener. The relevant JavaScript code appears below.
The outer table is "outerTable" the inner table with the working color change is "rollTable", and the inner table with the non-working visibility is "optionsTable". Note that the visibility-switching statements have been independently tested elsewhere and they work just fine, as exemplified by the inititializing call to setvis on the 'optionsTable' to hide it at the start! Note further that the alerts for 'doshow' and 'dohide' never fire, nor is there an error indication.
<script type="text/javascript">
var dored;
var doblue;
var doshow;
var dohide;
function registerEventListeners() {
var rt = document.getElementById("rollTable");
var ot = document.getElementById("optionsTable");
alert("register");
rt.addEventListener("mouseover",setred,false);
rt.addEventListener("mouseout",setblue,false);
dored = function() { rt.bgColor = "red" };
doblue = function() { rt.bgColor = "blue" };
setvis("optionsTable",-1);
alert("optionsTable");
doshow = function() {
alert("doshow");
ot.style.visibility="visible";
}
dohide = function() {
alert("dohide");
ot.style.visibility="hidden";
}
ot.addEventListener("mouseover",setshow,false);
ot.addEventListener("mouseout",sethide,false);
}
function setred() { dored(); }
function setblue() { doblue(); }
function setshow() { alert("setshow"); doshow(); }
function sethide() { alert("sethide"); dohide(); }
</script>
Many thanks for any and all help.