John Higgins John Higgins - 2 months ago 19
HTML Question

Display real time results in input box

I am trying to display the results of an input in real time in another disabled input box and am not having much luck. Code below:

var inputBox = document.getElementById('input');

inputBox.onkeyup = function(){
document.getElementById('output').innerHTML = inputBox.value*2;
}

<input type='text' id='input'>

<input type='text' id='output' disabled>


Can anyone help?

Thanks,

John

Answer

Try adding a listener and use value instead of innerHTML:

document.getElementById('input').addEventListener("keyup", myFunction);

var inputBox = document.getElementById('input');

function myFunction(){
    document.getElementById('output').value = inputBox.value*2;
}

JSfiddle: https://jsfiddle.net/22t37834/

Comments