HTML how to clear input using javascript?

Lucas Ferraz picture Lucas Ferraz · Jun 21, 2013 · Viewed 133.8k times · Source

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

The problem: I want to clear only if value = [email protected]

<script type="text/javascript">
    function clearThis(target) {
        target.value= "";
    }
</script>
<input type="text" name="email" value="[email protected]" 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.

Answer

David Scott picture David Scott · Jun 21, 2013
<script type="text/javascript">
    function clearThis(target) {
        if (target.value == '[email protected]') {
            target.value = "";
        }
    }
</script>

Is this really what your looking for?