Rollback999

How Can I Make My Searchbox Unclear/Clear with A Click?

Asked by Rollback999 2 years ago searchbox


Joel Reyes
0
 
Making a Searchbox clear is very simple, and about 90% of websites out there seem to employ this feature now…so it's pretty common. Here we'll use com JavaScript code, it should be used in correlation with your CSS (styling):

<script type="text/javascript">
    // searchbox functions ( clear & unclear )
    function clickclear(thisfield, defaulttext) {
        if (thisfield.value == defaulttext) {
            thisfield.value = "";
        }
    }

    function clickrecall(thisfield, defaulttext) {
        if (thisfield.value == "") {
            thisfield.value = defaulttext;
        }
    }
</script>

<input id="search" type="text" name="q" value="search" onclick="clickclear(this, 'search')" onblur="clickrecall(this,'search')"/>

by Joel Reyes 2 years ago

Answer this question

How Can I Make My Searchbox Unclear/Clear with A Click?

0 errors found:

 
0