Search code examples
javascriptphpclickenteronkeypress

Onkeypress enter search


hello I have a button search and I want when pressing enter make my search for the moment its work when onclick . 1) Can i HAve both ? 2) how do I do this correctly? Here my code

<script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript">
        function doSearch(){
            $('#tt').datagrid('load',{
                proNum: $('#proNum').val(),
                proName: $('#proName').val(),
                proCliId: $('#proCliId').val()
            });
        }
        function doSearch1(){
        if (e.keyCode == 13 || e.which == 13){
            $('#tt').datagrid('load',{
                proNum: $('#proNum').val(),
                proName: $('#proName').val(),
                proCliId: $('#proCliId').val()
            });
        }
        }
    </script>
</head>
<body>



    <table id="tt" class="easyui-datagrid" style="width:700px;height:500px"
            url="getdata.php"
            title="Searching" iconCls="icon-search" toolbar="#tb"
            rownumbers="true" pagination="true">
        <thead>

        </thead>
    </table>
    <div id="tb" style="padding:3px">
        <span>Entrer un chiffre ou une lettre pour débuter la recherche:</span>
        <input id="proNum"" style="line-height:26px;border:1px solid #ccc">
            <a href="#" onkeypress="doSearch1()" class="easyui-linkbutton" plain="true" onclick="doSearch()">Search</a>
    </div>
</body>
</html>

Solution

  •     function doSearch1(e){
        if (e.keyCode == 13){
            $('#tt').datagrid('load',{
                proNum: $('#proNum').val(),
                proName: $('#proName').val(),
                proCliId: $('#proCliId').val()
            });
        }