Question

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>
Was it helpful?

Solution

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

OTHER TIPS

1) Write a function that searches based on the input 2) Write a event handlers, a) capturing onkeypress->"ENTER" key b) capturing search click 3) Call the original search function from step 1

Your doSearch1 function probably doesn't work because it's trying to reference the event it looks like (through e) but you haven't named the first argument of your handler function e (it has no name)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top