HTML how to clear input using javascript?
<script type="text/javascript">
function clearThis(target) {
if (target.value == '[email protected]') {
target.value = "";
}
}
</script>
Is this really what your looking for?
you can use attribute placeholder
<input type="text" name="email" placeholder="[email protected]" size="30" />
or try this for older browsers
<input type="text" name="email" value="[email protected]" size="30" onblur="if(this.value==''){this.value='[email protected]';}" onfocus="if(this.value=='[email protected]'){this.value='';}">
For me this is the best way:
<form id="myForm">
First name: <input type="text" name="fname" value="Demo"><br>
Last name: <input type="text" name="lname"><br><br>
<input type="button" onclick="myFunction()" value="Reset form">
</form>
<script>
function myFunction() {
document.getElementById("myForm").reset();
}
</script>