Finding data from a dynamically created table

I created one application in which there is one text field for finding information from a table. Although I wrote the code when we enter a character in the search text box, after accepting one character control, it leaves the text box. this is my search code`

<script type="text/javascript"> $(document).ready(function() { var minlength = 1; $("#searchTerm").keyup(function () { value = $(this).val(); if (value.length > minlength ) { searchTable(value); } else if(value.length < minlength) { searchTable(""); } }); }); function searchTable(value) { $.ajax({ type: "GET", url: "dispatient.php", data:({search_keyword: value}), success: function(success) { window.location.href = "dispatient.php?search_keyword="+value; $("#searchTerm").focus(); }, error: function() { alert("Error occured.please try again"); }, complete: function(complete) { $("#searchTerm").focus(); }, }); } 
 <input id="searchTerm" Type="text" class="search_box" placeholder="Search" value = <?php echo $_GET['search_keyword'] ?> > 

`Please offer me ..

thanks in advance.

+6
source share
3 answers

value is the default javascript attribute trying to change the name of the value variable to something like searchData

+2
source

In your success callback, you redirect the page to dispatient.php. I believe that this is the same page on which there is a search function. After redirecting, the page reloads again, and there is no point in writing:

 $("#searchTerm").focus(); 

Since you are already using AJAX, try loading the grade data onto your page using JavaScript / jQuery without reloading the page.

+2
source

create one div and load your data instead of reloading the whole page.

try something like this instead of ajax Call

 <div id="searchResult"></div> $("#searchResult").load("search.php?search_keyword=value",function(){ //your callback }); 
+2
source

Source: https://habr.com/ru/post/983248/


All Articles