[thelist] javascript var question

Sarah Adams mrsanders at designshift.com
Wed May 3 13:55:16 CDT 2006

> Why does this work:
> document.getElementById("myinput").value = "my text";
> But this doesn't:
> var o = document.getElementById("myinput").value;
> o = "my text";

Because you're creating a variable which will hold the *value* of the 
myinput field rather than a "pointer" (not sure if this is the right 
term) to the value attribute. What you need to do is this:

var o = document.getElementById("myinput");
o.value = "my text";

sarah adams
web developer & programmer
portfolio: http://sarah.designshift.com
blog: http://hardedge.ca

More information about the thelist mailing list