2

I have what seemed to be a simple fix to a problem but after trying a ton of different solutions online nothing seems to work for me.

I have search field that searches a data table every time you type or press enter in the input field, however after I assigned a value to the search box when the page is loaded it wont do the search until after the user either presses enter in the box or types / deletes a letter. I was just trying to find a solution to simulate hitting enter but it didn't seem to work.

Here is my code:

<script type="text/javascript">
       window.onload = (function() {
           document.getElementById('search').value = " <?php echo $search;?>";

       });
</script>

This obviously assigns the value to what my php variable is set to which works fine the text is loaded in the box on page load, it just doesnt perform the search like I said unless the user presses enter in the box OR deletes/adds a letter in the input box.

The search box code is

<input type="text" id="search" aria-controls="DataTables_Table_0" class="text">

Update: This is documentation I found on exactly what I am using http://datatables.net/ref

4

4 回答 4

1

尝试这个

document.getElementById("formId").submit();
于 2012-10-12T19:46:57.913 回答
0

您可以在 javascript 中调用该onchange()事件:

<script type="text/javascript">
   window.onload = (function() {
       document.getElementById('search').value = " <?php echo $search;?>";
       document.getElementById('search').onchange();
   });
</script>

这个答案也有另一种选择:https ://stackoverflow.com/a/3629423/890726

于 2012-10-12T19:47:55.283 回答
0
       <input type="text" id="fname" onblur="businessFun()">

Please try this and in js buinessFun() do the search actions if you use ajax pass current time as parameter

于 2012-10-12T19:56:42.643 回答
0

我假设您有一个表单,在文本框中输入将触发表单的提交。在javascript中,您可以像这样手动执行此操作:

<form id='myform" action="/foo">

document.forms["myform"].submit();
于 2012-10-12T19:48:39.313 回答