Loading ...
Sorry, an error occurred while loading the content.

Event Listener ++ onblur event of text field ++

Expand Messages
  • pannet1@yahoo.com
    Dear List, I am trying to use the event listener for changing focus to specific fields on my form. In the below example I want to shift the focus from text
    Message 1 of 2 , Apr 28, 2007
    • 0 Attachment
      Dear List,

      I am trying to use the event listener for changing focus to specific fields on my form. In the below example
      I want to shift the focus from text field tab1 to tab3. But the YAHOO.util.Event.addListener("tab1","onblur", grabfocus);
      never seems to work.

      What am I doing wrong ? can you please help. I have given below the complete listing.


      http://www.w3.org/TR/html4/strict.dtd">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

      <script type="text/javascript" src="js/yahoo.js"></script>
      <script type="text/javascript" src="js/event.js"></script>
      <script type="text/javascript" src="js/dom.js"></script>
      <script type="text/javascript" src="js/dragdrop.js"></script>


      <style type="text/css">
      #intro {padding:10px; background-color:#EEEEEE; font-style:italic; font-size:92%;}
      #container {width:400px; height:65px; padding:10px; border:1px dotted black;background-color:#CCCCCC;}
      </style>
      <script>

      (function() {

      var tabkey = 1;

      //A function that pops up a "Hello World" alert:
      var helloWorld = function(e) {
          alert ("helloworld");
      }

      //subscribe the helloWorld function as an event
      //handler for the click event on the container
      //div:
      YAHOO.util.Event.addListener("container", "click", helloWorld);

      //this never executes
      var grabfocus = function(e) {
         
          YAHOO.util.Event.preventDefault(e);   
         
          this.document.eventform.tabkey.focus();
         
          // update global tabkey variable
          // to know this field had lost
          // focus
          tabkey = 3;        
      }

      YAHOO.util.Event.addListener("tab1","onblur", grabfocus);
       
      })();

      </script>
      <title>Simple Event Handling</title>
      </head>
      <body>
      <h1>Simple Event Handling</h1>
      <form name=eventform>
      <div id="container">
          <p>Click for Hello World alert.</p>
      </div>
      <div id="tab1">
          tab1: <input type="text" name="tab1">
      </div>
      <div id="tab2">
          tab2: <input type="text" name="tab2">
      </div>
      <div id="tab3">
          tab3: <input type="text" name="tab3">
      </div>
      </form>
      </body>
      </html>

      Best Regards
      B Karthick



      Ahhh...imagining that irresistible "new car" smell?
      Check out new cars at Yahoo! Autos.
    • Adam Moore
      ... Use blur instead of onblur : YAHOO.util.Event.addListener( tab1 , blur , grabfocus); -Adam
      Message 2 of 2 , Apr 30, 2007
      • 0 Attachment
        On Sat, Apr 28, 2007 at 03:21:17AM -0700, pannet1@... wrote:
        > Dear List,
        >
        > I am trying to use the event listener for changing focus to specific fields on my form. In the below example
        > I want to shift the focus from text field tab1 to tab3. But the YAHOO.util.Event.addListener("tab1","onblur", grabfocus);
        > never seems to work.

        Use "blur" instead of "onblur":

        YAHOO.util.Event.addListener("tab1", "blur", grabfocus);

        -Adam
      Your message has been successfully submitted and would be delivered to recipients shortly.