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!


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

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



for jQuery we can use below:

by input name:

$('input[name="textboxname"]').val('some value');

by input class:

$('input[type=text].textboxclass').val('some value');

by input id:

$('#textboxid').val('some value');

Need Your Help

AngularJS: Uncaught Error: [$injector:modulerr] Failed to instantiate module?

angularjs jsfiddle angularjs-module

I am new to AngularJS and working my way through some documents and tutorials to learn. My question is in reference to Egghead's video series, this video in particular, demonstrating how to put tog...

Possible to reverse a css animation on class removal?

javascript jquery html css css3

Essentially what I'm trying to do is give an element a CSS animation when it gains a class, then reverse that animation when I remove the class without playing the animation when the DOM renders.