Speedding Speedding - 1 year ago 62
Javascript Question

Javascript - fill in the textbox dynamically

Is it possible to fill textbox using javascript?
I have this code

<input type="text" id="output">

After using the script, I want to have selected value in textbox. I'm very new to javascript and I tried this

javascript: document.getElementById('output').innerHTML = "100";

However, it doesn't work as I expected. So after using the script I want HTML look like

<input type="text" id="output" value="100">

Is there any way to manage this? Thanks

Answer Source

You can use .value or .setAttribute.

document.getElementById('output').value = "100";


document.getElementById('output').setAttribute("value", "100");