Form Search Onkeyup event
Posted
by
Aryan
on Stack Overflow
See other posts from Stack Overflow
or by Aryan
Published on 2012-12-19T05:01:42Z
Indexed on
2012/12/19
5:02 UTC
Read the original article
Hit count: 173
I Have a Form In which the form should automatically search when i complete entering the 10th character in the text field but the below code is searching for each n every character i enter in the text field . . . I just want the result after completing the 10th character not for each n every character . . i have used onkeyup event and i set that value to 10 but still it is searching for each n every character... please do help me
<body OnKeyPress="return disableKeyPress(event)">
<section id="content" class="container_12 clearfix" data-sort=true>
<center><table class='dynamic styled with-prev-next' data-table-tools='{'display':true}' align=center>
<script>
function disableEnterKey(e)
{
var key;
if(window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox
return (key != 13);
}
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
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("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","resdb.php?id="+str,true);
xmlhttp.send();
}
</script>
<script type='text/javascript'>
//<![CDATA[
$(window).load(function(){
$('#id').keyup(function(){
if(this.value.length ==10)
});
});//]]>
</script>
<form id="form" method="post" name="form" >
<tr><td><p align="center"><font size="3"><b>JNTUH - B.Tech IV Year II Semester (R07) Advance Supplementary Results - July 2012</b></font></p></td></tr>
<td><p align="center"><b>Last Date for RC/RV : 8th August 2012</b></p></td>
<tr><td><p align="center"></b> <input type="text" onkeyup="showUser(this.value)" onKeyPress="return disableEnterKey(event)" data-type="autocomplete" data-source="extras/autocomplete1.php" name="id" id="id" maxlength="10" placeholder=" Hall-Ticket Number"> </p></td></tr>
</table>
</center>
</form>
<center>
<div id="txtHint"><b>Results will be displayed here</b></div>
</center>
</body>
© Stack Overflow or respective owner