Use getElementsByName to get the elements and Set the value property. If multiple elements then Loop over the array and set each element’s value.
Example JavaScript set input value by name
HTML example code set input value programmatically using JS.
<html>
<body>
<input type="text" name="in1" >
<script>
var els=document.getElementsByName("in1");
els.value = "Test Content"
</script>
</body>
</html>
Output:
Do comment if you have any doubts and suggestions on this topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version