www.webdeveloper.com
Results 1 to 2 of 2

Thread: Problem in onkeyup event

  1. #1
    Join Date
    Oct 2011
    Posts
    350

    Problem in onkeyup event

    Hi...

    i got problem in using this code:
    Code:
    <script>
     window.onload = function() { 
      var ul = document.getElementById('searchpayroll');
      var links = ul.getElementsByTagName('a');
      var i = 0;
     
     document.onkeyup = function(e){ 
      
     e = window.event || e;
       
       var key = e.charCode || e.keyCode;
    
          if (key == 40) { 
          // up pressed
          if (i < links.length - 1) i++; 
        }
        else if (key == 38) {
          // down pressed
          if (i > 0) i--;
        }
        // focus on link
        
        
       links[i].focus();
       
        // request content in here for link with ajax
       // alert(links[i].href);
      }
    }
    </script>
    <div id="Search">
    <form>
    <p class="serif"><b>Search Lastname:</b></p>
    <input type="text" name="search_" size="20" onkeyup="searchemppay(this.value);">
    <!--<div id="searchpayroll" style="overflow:auto; height:390px; width:auto; margin-left:2px" >-->
    <hr />
    <ul id="searchpayroll" style="overflow:auto; height:385px; width:auto; margin-left:2px;">
    <!--<ul>-->
    {section name=co_emp loop=$personalAll}
    <!--<li onclick="changeEmployeePay('{$personalAll[co_emp].EMP_ID}')">{$personalAll[co_emp].FULLNAME}</li> -->
    <li><a href="SearchData.php?queryEmpID={$personalAll[co_emp].EMP_ID}">{$personalAll[co_emp].FULLNAME}</a></li>
    <hr />
    {sectionelse}
    <li>No records found</li>
    {/section}
    </ul>
    </div>
    the problem is...when I type in search textfield it focus in the name list..like for example i type a after I press a it was focus in the firstname, which is wrong..

    I think it cause from the javascript code..

    I want to happen is i continue typing in search textfield like what happen before I used script for keyevent.

    Thank you

  2. #2
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131
    Code:
    var links = ul.getElementsByTagName('a');
    ...
    ...
    ...
    links[i].focus();
    of course it will focus on one of the links... Thats where your putting the focus.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles