Roy Gardiner
03-18-2005, 04:53 PM
<HTML onClick="alert('Event is now at the HTML element.')">
<HEAD>
<TITLE>Event Bubbles</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function init() {
window.onclick = winEvent
document.onclick = docEvent
document.onfocus = focEvent
document.body.onclick = docBodEvent
}
function winEvent() {
alert("Event is now at the window object level.")
}
function docEvent() {
alert("Event is now at the document object level.")
}
function focEvent() {
alert("Focus is now at the document object level.")
}
function docBodEvent() {
alert("Event is now at the BODY element.")
}
</SCRIPT>
</HEAD>
<BODY onLoad="init()">
<H1>Event Bubbles</H1>
<HR>
<FORM onClick="alert('Event is now at the FORM element.')">
<INPUT TYPE="button" VALUE="Button 'main1'" NAME="main1"
onClick="alert('Event started at Button: ' + this.name)"
onFocus="alert('here: ' + this.name)">
</FORM>
</BODY>
</HTML> The above taken from the Javascript Bible. Clicking on the button gives the correct set of messages about event hierachy. I have added the bits about focus and no doubt coded it wrong, because tabbing to the button to give it the focus gives me just the focus event on the button, nothing else; what have I done wrong?
Sorry if it's trivial, but my brain has stopped working.
<HEAD>
<TITLE>Event Bubbles</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function init() {
window.onclick = winEvent
document.onclick = docEvent
document.onfocus = focEvent
document.body.onclick = docBodEvent
}
function winEvent() {
alert("Event is now at the window object level.")
}
function docEvent() {
alert("Event is now at the document object level.")
}
function focEvent() {
alert("Focus is now at the document object level.")
}
function docBodEvent() {
alert("Event is now at the BODY element.")
}
</SCRIPT>
</HEAD>
<BODY onLoad="init()">
<H1>Event Bubbles</H1>
<HR>
<FORM onClick="alert('Event is now at the FORM element.')">
<INPUT TYPE="button" VALUE="Button 'main1'" NAME="main1"
onClick="alert('Event started at Button: ' + this.name)"
onFocus="alert('here: ' + this.name)">
</FORM>
</BODY>
</HTML> The above taken from the Javascript Bible. Clicking on the button gives the correct set of messages about event hierachy. I have added the bits about focus and no doubt coded it wrong, because tabbing to the button to give it the focus gives me just the focus event on the button, nothing else; what have I done wrong?
Sorry if it's trivial, but my brain has stopped working.