表单搜索Onkeyup事件

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">&emsp;</p></td></tr>
        </form>
    </center>
</table>
<center>
    <div id="txtHint"><b>Results will be displayed here</b></div>
</center>
</body>

1个回答


这是一个想法,因为您的代码正在运行。 这样做。 首先检查您的文本字段是否超过10个字符。 呼叫fnc()onkeyup </ p>

 函数fnc()
  {
   length = document.getElementById(“ atext”)。value.length;
   如果(长度== 10)
   {
       callyourajaxfunction()
    }

}
</ code> </ pre>
     </ div>

展开原文

原文

This is an idea as your code is working. Do it this way. First check your textfield if it is more than 10 character or not. call fnc() onkeyup

function fnc()
 {
  length=document.getElementById("atext").value.length;
  if(length==10)
  {
      callyourajaxfunction()
   }


}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐