Working search box for website and blog

High speed Working  search box for website and blog with a list of search items with filter



We are searching for a search box now a days for our website but all of the search boxes are made by search engines using custo search. Which is not a satisfying factor for us.The custom search engine contains ads as their wish and going to their domain for ther search results. So why won't we think of our own search box with our own design. We made a search engine using lists and they will display in boxes.







As in the video , search results are found in seconds. The results are already given below as a list. When we search,it works like a filter showing the search results only. If you did not want the list as listed below then go to the code section of the site and there we made another search box which did not show the list and shows the list only when we click on the search bar.


The code given below contains CSS for the style of the search box, JavaScript for the working of the search box to find the search results and finally the html code for the webpage.



<!DOCTYPE html>

<html>

<head>

<meta name="viewport" content="width=device-width, initial-scale=1">

<style>

* {

  box-sizing: border-box;

}


#myInput {
  background-image: url('/css/searchicon.png');
  background-position: 10px 12px;
  background-repeat: no-repeat;
  width: 100%;
  font-size: 16px;
  padding: 12px 20px 12px 40px;
  border: 1px solid #ddd;
  margin-bottom: 12px;
}

#myUL {
  list-style-type: none;
  padding: 0;
  margin: 0;
}

#myUL li a {
  border: 1px solid #ddd;
  margin-top: -1px; /* Prevent double borders */
  background-color: #f6f6f6;
  padding: 12px;
  text-decoration: none;
  font-size: 18px;
  color: black;
  display: block
}

#myUL li a:hover:not(.header) {
  background-color: #eee;
}
</style>
</head>
<body>

<h2>My languages</h2>

<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name">

<ul id="myUL">
  <li><a href="#">java</a></li>
  <li><a href="#">c</a></li>

  <li><a href="#">css</a></li>
  <li><a href="#">c++</a></li>

  <li><a href="#">python</a></li>
  <li><a href="#">sql</a></li>
  <li><a href="#">julia</a></li>

</ul>

<script>
function myFunction() {
    var input, filter, ul, li, a, i, txtValue;
    input = document.getElementById("myInput");
    filter = input.value.toUpperCase();
    ul = document.getElementById("myUL");
    li = ul.getElementsByTagName("li");
    for (i = 0; i < li.length; i++) {
        a = li[i].getElementsByTagName("a")[0];
        txtValue = a.textContent || a.innerText;
        if (txtValue.toUpperCase().indexOf(filter) > -1) {
            li[i].style.display = "";
        } else {
            li[i].style.display = "none";
        }
    }
}
</script>

</body>
</html>

Comments

Popular posts from this blog

Node.js Cheat Sheet

Codeigniter ! Simple But Powerful

Introducing Cloudflare Pages ⚡