0

javascript innerHTML is not updating the value of input field

 var i = document.getElementById("inp-text");
 i.innerHTML = 'hello';
<!DOCTYPE html>
<html>
<head>
 <title>Java Script innerHTML not working</title>
</head>
<body>
<input type="text" id="inp-text" name="" />

</body>
</html>
  • innerHTML is a DOM property to insert content to a specified id of an element. It is used in Javascript to manipulate DOM. `innerHTML` is only used to insert new elements and `value` is used for inserting value in input field and textarea – Smit Dec 18 '16 at 15:18

1 Answers1

6

For forms elements, you need to update value property for updating the content.

var i = document.getElementById("inp-text");
i.value = 'hello';
<input type="text" id="inp-text" name="" />
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188