2 Replies Latest reply: Dec 22, 2009 8:06 AM by Phil_W RSS

    Unobstrusive event handling with Spry

    Phil_W Community Member

      Hi,

       

      I've got this

       

      In one of my javascript files I have the function

       

      function storeCaret(mytext) {


          
           if (mytext.createTextRange) {
               mytext.caretPos = document.selection.createRange().duplicate();
           }
      }

       

      In my source I have

       

      <textarea name="ReplyQuote"  rows="10" id="ReplyQuote" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onchange="storeCaret(this);">Text in here</textarea>

       

       

      Which has various event handlers that I would like to make unobtrusive.

       

      I've tried

       

      Spry.$$('#ReplyQuote').addEventListener("change",storeCaret(this),false);
      Spry.$$('#ReplyQuote').addEventListener("click",storeCaret(this),false);
      Spry.$$('#ReplyQuote').addEventListener("keyup",storeCaret(this),false);
      Spry.$$('#ReplyQuote').addEventListener("select",storeCaret(this),false);

       

      But it's just not returning the correct reference to the function storeCaret.  So I guess my understanding of this needs improving.  How do I ensure I pass the same reference unobtrusively?

       

      Thanks

       

      Phil