473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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);
}

Jun 27 '08 #1
3 3788
On Apr 23, 5:42 pm, Brent wrote:
... , 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.
-------------------------------------------------------------------
function makeEditable(el)
{
thisEl = el.contentWindow.document;
<snip>
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.
Jun 27 '08 #2
On Apr 23, 10:21*am, Henry <rcornf...@raindrop.co.ukwrote:
On Apr 23, 5:42 pm, Brent wrote:
... , 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.
-------------------------------------------------------------------
function makeEditable(el)
{
* * thisEl = el.contentWindow.document;
<snip>
* * 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.- Hide quoted text -

- Show quoted text -
thisEl.document.body.onkeyup ?
Jun 27 '08 #3
On May 8, 4:42 am, Freeform wrote:
On Apr 23, 10:21 am, Henry wrote:
>On Apr 23, 5:42 pm, Brent wrote:
>>... , 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.
-----------------------------------------------------------------
function makeEditable(el)
{
thisEl = el.contentWindow.document;
<snip>
>> 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.- Hide quoted text -
^^^^^^^^^^^^^^^^^^^^
>- Show quoted text -
^^^^^^^^^^^^^^^^^^^^
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)?
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Trent | last post by:
Hi. I know the basic way to assign event handlers: <input onKeyUp="processEvent(event)" /> But how do I assign a function to the onKeyUp event in *javascript* that can access the event...
2
by: Evan Wong | last post by:
I have problem to get onkeyup event. If we put the event in HTML statement like - "<input name=field1 size=16 onkeyup="javascript:function1();>" it works. If we put in JavaScript code like...
3
by: Brad | last post by:
The first text on my form is a numeric field. I have a javascript that runs on this field for onkeyup (validate the key strokes and modifies fields on the screen) but when I do this and have the...
4
by: TS | last post by:
I am creating a User control and i create some dynamic controls in the init handler. one of the controls is a custom validator which i assign a serverValidate event handler. I usally always do my...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
2
by: mc | last post by:
Can someone suggest how I would add a new trigger such that when the JS event onkeyup in a textbox the updatePanel refreshes? If not could someone sugest how I could onkepup in a Textbox, refresh...
1
by: manojsharma | last post by:
hey can anybody tell me y my onkeyup event is not working in firefox.. it is working fine in IE... code <input type="text" name="oddteam" size="1" value="1" ...
8
by: Tony Johansson | last post by:
Hello! I wonder can somebody explain when is it suitable to use these methods OnKeyUp, OnKeyDown and OnKeyPress because these raise an event. These are located in class UserControl. If these...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.