Originally Posted by aalexaa
and it won't work.
but when i add an extra line,
alert(x+" "+y) to tell me what the value of each input is, both values are the same. but the text won't show up in the second input field.
well, it does work, just not the way you think it works.
in general, everything besides the primitives is passed by reference*, thus in the beginning x and y point to the two input’s value attributes. when you do
x = y
x points now to the same value attribute as y, without doing anything to the previous assigned value.
var x = document.getElementById("fname");
var y = document.getElementById("dname");
x.value = y.value;
* - can be annoying when working with arrays