How to clear input in Javascript?
JavaScript Clear Input
1. Use the onfocus Attribute to Vanish Input Field in JavaScript.
2. Use Conditional Statement to Clear Form Input Value in JavaScript.
3. Use the reset() Method to Erase Form Input Fields in JavaScript.
javascript clear input string
inputField.value = " ";
Example 2
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>test</title>
</head>
<body>
<input type="text" value= "abc@gmail.com" onfocus="clearF(this)">
<script>
function clearF(target) {
if (target.value == 'abc@gmail.com') {
target.value = "";
}
}
</script>
</body>
</html>
Output
