I want to set an HTML field's value using JavaScript when onclick
event is raised by clicking a button/hyperlink.. I Googled and found many articles using the name
attribute, but I want to set the value using the field's id
only.
The id attribute assigns an identifier to the <input> element. The id allows JavaScript to easily access the <input> element. It is also used to point to a specific id selector in a style sheet.
Change the Input Value Using the setAttribute() Function in JavaScript. We can also use the setAttribute() function instead of the value property to set the input value. We can also use the forms() function instead of the getElementById() or querySelector() function to get the element using the form name and input name ...
document.getElementById('Id').value='new value';
https://developer.mozilla.org/en-US/docs/Web/API/document.getElementById
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