Search code examples
javascripthtmlinputerase

HTML how to clear input using javascript?


I have this INPUT, it will clear everytime we click inside of it.

The problem: I want to clear only if value = exemplo@exemplo.com

<script type="text/javascript">
    function clearThis(target) {
        target.value= "";
    }
</script>
<input type="text" name="email" value="exemplo@exemplo.com" size="30" onfocus="clearThis(this)">

Can someone help me to do this? I don't know how to compare, I already tried but no success.


Solution

  • <script type="text/javascript">
        function clearThis(target) {
            if (target.value == 'exemplo@exemplo.com') {
                target.value = "";
            }
        }
    </script>
    

    Is this really what your looking for?