उदाहरण
onclick इवेंट और value = '' से टेक्स्ट फील्ड क्लियर करें।
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="text" id="txtBox" placeholder="Enter the value...."/>
<button type="button" id="clear" onclick="clearTheTextField()">ClearInputText</button>
<script>
function clearTheTextField() {
console.log("The text box value=" + document.getElementById('txtBox').value);
document.getElementById('txtBox').value = '';
}
</script>
</body>
</html>
फ़ाइल सेव करें और Live Server से खोलें।
आउटपुट
बटन क्लिक करने पर टेक्स्ट बॉक्स खाली हो जाएगा।