0

I have a simple html:

<td><input type="text" style="border:none;" size="12" id="titleId" name="title" value="333"></td>

and I use the code below to update the value of the input:

document.getElementById('titleId').value = "999";

However, when I click "inspect element" the value is still "333", but on the page it shows "999". I need to update the value to "999" for pdf printing purposes.

How can I update the values using js?

Nessi
  • 276
  • 1
  • 4
  • 23
  • 3
    No, the `value` _attribute_ might still be `333` but the `value` property will be changed which is what is reflected in the text value of the `` (ie, what you see). Changes to element properties aren't always reflected in their attributes. Think of attributes as a value initialiser only – Phil Dec 16 '19 at 06:18
  • How can I do what I need? (change value attribute) – Nessi Dec 16 '19 at 06:21
  • You shouldn't need to – Phil Dec 16 '19 at 06:21

1 Answers1

4

In addition to @Phil's Comment, this is how you can change attribute's value via javascript

function test(){
  document.getElementById("in").setAttribute("value", "999");
}
<input id="in" value="333"/>
<button onclick="test()">Click Me</button>
Ahmed Ali
  • 1,908
  • 14
  • 28