How to add on key down and on key up event in java script

Posted by Ramesh on Stack Overflow See other posts from Stack Overflow or by Ramesh
Published on 2010-05-08T12:30:13Z Indexed on 2010/05/08 12:38 UTC
Read the original article Hit count: 265

Filed under:
|

Hello , I am creating an live search for my blog..i got this from w3 schools and i need to add on keyboard up,down mouse up and down event ...

<html>
<head>
<script type="text/javascript">
function showResult(str)
{
if (str.length==0)
  {
  document.getElementById("livesearch").innerHTML="";
  document.getElementById("livesearch").style.border="0px";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
    document.getElementById("livesearch").style.border="1px solid #A5ACB2";
    }
  }
xmlhttp.open("GET","livesearch.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<form>
<input type="text" size="30" onkeyup="showResult(this.value)" />
<div id="livesearch"></div>
</form>

</body>
</html> 

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html