What do you think of this solution?
const inputField = document.getElementById('myFormField');
const icon = document.getElementById('myIcon');
inputField.onchange = function(){
icon.src = this.value ? 'success.png' : 'fail.png';
};
(I have not had the chance to try this out yet)
In simple terms, this code instructs the browser to check the value of a form field upon user input. If the field is empty, the icon displayed will change accordingly.
For different types of form fields like select menus, you may need to use a different property instead of value
. With jQuery, you can simply utilize .val().
To improve this functionality, consider adding more complex validation such as checking for whitespaces in the field's value.