I have input field with id txt1 but I am unable to change the value from JavaScript.
<form action="">
First name: <input type="text" id="txt1" onkeyup="showHint(this.value)">
</form>
<script>
document.getElementById('txt1').value('anyvalue1111');
</script>
Note: I find on stackoverflow how to change input value but could not found any answer. Title of the question save lot of time. It is valid question in this way.
value
is a property and not a method.
document.getElementById('txt1').value = 'anyvalue1111';
Try this
<form action="">
First name: <input type="text" id="txt1" onkeyup="showHint(this.value)">
</form>
<script>
document.getElementById('txt1').value = 'Hello world!!';
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With