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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brent

    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.contentWindo w.document;
    try
    {
    if(thisEl.body. contentEditable )
    {thisEl.body.co ntentEditable = true;}
    else
    {thisEl.designM ode = "on";}
    }
    catch(e)
    {
    alert(e);
    }
    thisEl.body.sty le.fontFamily = "verdana, arial, helvetica, sans-
    serif";
    thisEl.body.sty le.fontSize = "12px";
    thisEl.body.sty le.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);
    }

  • Henry

    #2
    Re: onKeyUp event not firing...or just bad code?

    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.contentWindo w.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.

    Comment

    • Freeform

      #3
      Re: onKeyUp event not firing...or just bad code?

      On Apr 23, 10:21 am, Henry <rcornf...@rain drop.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.contentWindo w.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 ?

      Comment

      • Henry

        #4
        Re: onKeyUp event not firing...or just bad code?

        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.contentWindo w.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)?

        Comment

        Working...