weixin_33682790 2012-12-19 05:01 采纳率: 0%
浏览 122

表单搜索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条回答

  • weixin_33724059 2012-12-19 05:12
    关注

    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()
       }
    
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!