The following does not render any change I can see in Chrome or Firefox:
var field = document.getElementById( 'input-id' ), nodeName;
if ( field !== null ) {
nodeName = field.nodeName.toLowerCase();
if( nodeName === 'input' || nodeName === 'textarea' ) {
field.value = 'hello';
console.log( field.value );
}
}
Here is the target:
<input id="input-id" name="input-name" type="text" required="required" placeholder="example">
But the console reports the correct value in both. Why? I am using validated HTML5. The script is before the closing body tag.
===is this is issue ? can you change==and see? Might be assignment and type together is the issue ?valueproperty does. @Sahal That’s just a comparison operator with a strict type check. It wouldn’t have any effect on the value of the input.