JavaScript set input value by id | Simple HTML example

Use id and getElementById method to Change the value of a text field using JavaScript.

This is one way of doing it:

Example JavaScript set input value by id

HTML Example code Set the value of an input field using JS:-

You can write the code in JavaScript as given below to set its value as

Output:

Example JavaScript set input value by id

Do comment if you have any doubts and suggestion on this topic.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.