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

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题