Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-19-2011, 01:00 AM   PM User | #1
newphpcoder
Regular Coder

 
Join Date: Aug 2010
Posts: 653
Thanks: 155
Thanked 0 Times in 0 Posts
newphpcoder is an unknown quantity at this point
Problem in Search

Hi

Before, I got a problem in using arrow up and down key in choosing employee name.. And now with the help of other I fixed it, but now I got an problem when I search the name of employee his data was not displayed. And also when i type in search field after I type one letter it focus/fall in the name list..it wrong..it would be the cursor will stick in the textfield while I'm typing letters.

Here is my new code:
left.tpl
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 == 38) {
      if (key == 40) { 
      // up pressed
      //if (i < links.length - 1) i++;
      if (i < links.length - 1) i++; 
    }
    else if (key == 38) {
      // down pressed
      if (i > 0) i--;
     // 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>
</div>
and the javascript code:
Code:
<script>
function searchemppay(queryString) {
    
    var ajaxRequest = remoteRequestObject();
    ajaxRequest.onreadystatechange = function() {
        if (ajaxRequest.readyState == 4 && ajaxRequest.status == 200) {
            var result = ajaxRequest.responseText;
            document.getElementById('searchpayroll').innerHTML = result;
        } 
    }
    var url = "search.php?query=" + queryString; 
    ajaxRequest.open("GET", url, true);
    ajaxRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    ajaxRequest.send(null);

}

function changeEmployeePay(queryID) {

window.location = "SearchData.php?queryEmpID=" + queryID;
}
</script>
search.php //where i encountered problem
Code:
<?php

session_start();
include 'config.php';

$queryString = $_GET["query"];

$queryStr = trim($_GET["queryEmpID"]);

$_SESSION['empID'] = $queryStr; 

if ($queryString == "" || $queryString == null) {

$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL 
        ORDER BY FULLNAME ASC";
}
else {
$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL WHERE LNAME LIKE '" . $queryString . "%' ORDER BY FULLNAME ASC";

}

$recPersonalQuery = $conn->Execute($sql);
if (!$recPersonalQuery->BOF) {
    $recPersonalQuery->MoveFirst();
}

echo "<hr />";
echo "<ul>";
while (!$recPersonalQuery->EOF) {
    $empID   = $recPersonalQuery->fields["EMP_ID"]; 
    $empFullName = $recPersonalQuery->fields["FULLNAME"];
    echo "<a href='SearchData.php?queryEmpID=('$empID')'; style= 'font-family:'Times New Roman',Times,serif; font-size:10%;'>$empFullName</li>";
    echo "<hr />";
    $recPersonalQuery->MoveNext();
} 
echo "</ul>";

$recPersonalQuery->Close();
exit();    

?>
and the SearchData.php
Code:
<?php
session_start();

$queryStr = trim($_GET["queryEmpID"]);

$_SESSION['empID'] = $queryStr; 

session_write_close();
header("Location:DisplayEmpPayroll.php");
exit();
?>
I hope someone can help me to resolved this another issue..

But I tried also to fix it..

Thank you so much..
newphpcoder is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:23 AM.


Advertisement
Log in to turn off these ads.