onKeyUp event not firing...or just bad code?

B

Brent

The code below correctly sets an iframe to be editable, and then tries
to attach an "onkeyup" event to the iframe. Instead of doing that,
however, it generates a cryptic "Object required" error in Explorer 7,
and doesn't seem to do anything at all in Firefox. Am I missing
something really basic?

Thanks for any help.

--Brent


--------------------------------------------------------------------------
function makeEditable(el)
{
thisEl = el.contentWindow.document;
try
{
if(thisEl.body.contentEditable)
{thisEl.body.contentEditable = true;}
else
{thisEl.designMode = "on";}
}
catch(e)
{
alert(e);
}
thisEl.body.style.fontFamily = "verdana, arial, helvetica, sans-
serif";
thisEl.body.style.fontSize = "12px";
thisEl.body.style.margin = "1px";

thisEl.onkeyup = checkKeys; //<--doesn't seem to register the
event
}

function checkKeys(e)
{

var event = e ? e : window.event;
var KeyID = event.keyCode;
alert(KeyID);
}
 
H

Henry

... , it generates a cryptic "Object required" error in Explorer 7,
and doesn't seem to do anything at all in Firefox. Am I missing
something really basic?

Thanks for any help.
thisEl.onkeyup = checkKeys; // ...

}

function checkKeys(e)
{

var event = e ? e : window.event; ^^^^^^^^^^^^
var KeyID = event.keyCode;
<snip> ^^^^^^^^^^^^^

In IE, you are assigning the keyup listener to the document in the
IFRAME (as you must) but the code in the assigned function is looking
for the event in the window that contains the IFRAME, which is not the
window in which the events are happening.
 
F

Freeform

                          ^^^^^^^^^^^^>     var KeyID = event.keyCode;

<snip>            ^^^^^^^^^^^^^

In IE, you are assigning the keyup listener to the document in the
IFRAME (as you must) but the code in the assigned function is looking
for the event in the window that contains the IFRAME, which is not the
window in which the events are happening.- Hide quoted text -

- Show quoted text -

thisEl.document.body.onkeyup ?
 
H

Henry

^^^^^^^^^^^^^^^^^^^^
Why are you including meaningless text in your posts, and most
especially, why have you attributed that text to me?
thisEl.document.body.onkeyup ?

What (and why)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top