Search Text Box Clear Button

Listen Audio
0:00 / 0:00
Search text box clear button image

We have recorded a video on this article. You will be able to access it once you have logged in. Please log in to watch the video.

this is an example how to clear input value when click a clear button in search box . create a search form to demonstrate this task

div #serchhide{
    display:none;
    cursor:pointer
}

then create a search form

<form action="" method="post">
     <div class="input-container-search">
	    <input type="search" name="search_query" id="search_query" onkeyup="searchsuccess()"  placeholder="Search here..."/>               
                <span  onclick="searchclear()">
	             <i id="serchhide" class="fas fa-times eyes" onclick="searchclear()"></i>
	             </span>                  
               <button type="submit" name= "search" class="searchicon">
            </button>
	  </div>
</form>

the out put will be as seen below


then apply a JavaScript function to clear the input value.

function searchsuccess() {
     var search_value = document.getElementById("search_query").value;
	 if(search_value.length >= 1) { 
            document.getElementById('serchhide').style.display="block"; 
        }
        else { 
            document.getElementById('serchhide').style.display="none";         
        }
    }
function searchclear() {
    document.getElementById("search_query").value="";
    document.getElementById('serchhide').style.display="none";
}

that's all about for this task.



Leave a non public comment how to improve it.



Characters Remaining

We are sorry for your bad experience. Leave a non public comment how to improve it.



Characters Remaining

Related Posts (5)

add prism code snippet in to a website image
using Line Numbers in code snippet   image
Email Verification using JavaScript image
CHECK FORM VALIDATION without loading a page using AJAX image
9th topics image

Share this on

Search


Archives

No archives data found yet in 2016.

Find Us on Facebook

Subscribe for new updates



Back to Top