input value empty javascript code example

Example 1: how to make input field empty in javascript

Assuming the element you want to change has the id question, so you can do

document.getElementById("question").value = "";

Example 2: how to check if all inputs are not empty with javascript

const inputFeilds = document.querySelectorAll("input");

const validInputs = Array.from(inputFeilds).filter( input => input.value !== "");

console.log(validInputs) //[array with valid inputs]

Example 3: js remove value input

document.getElementById("YourID").value = '';

Example 4: js clear text in input

<input type="text" value="A new value" onfocus="if(this.value=='A new value') this.value='';">

Tags:

Css Example