Jay Wit Jay Wit - 2 years ago 122
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 Source

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

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download