Jay Wit Jay Wit - 6 months ago 26
HTML Question

Change value of input onchange?

I want a very simply Javascript function (which I can't get to work, not so simple for me).

When Someone inserts a number in an inputfield, the value of an other inputfield should change to that value. I have atm:

function updateInput(ish) {
fieldname.value = ish;
}
<input type="text" name="fieldname" id="fieldname" />
<input type="text" name="thingy" onchange="updateInput(value)" />


But this doesn't work somehow, can someone help me out?

Thanks in advance!

Answer

You can't access your fieldname as a global variable. Use document.getElementById:

function updateInput(ish){
    document.getElementById("fieldname").value = ish;
}

and

onchange="updateInput(this.value)"
Comments