For the input element , the default value indicated by the value attribute, and the current value indicated by the value property.
A textarea is different. The default value is specified in the text node, which is a child of this element.
i.e:.
<textarea>this is the default value</textarea>
However, the current value is still determined by the value property.
document.getElementById('thefield').value = 'value';
... although the value attribute is missing for textarea elements.
You can change the default value ( input.setAttribute("value", "new value") or textarea.innerHTML = "new value" ), which will be:
- Change the displayed value if it has not changed (for example, when entered by the user)
- Change the value that the reset control will have if the reset button is activated
... but usually you need to change (and read) the current value, which will always be input.value / textarea.value .
source share