View Full Version : Behavior of getAttribute("value")

01-26-2007, 07:41 PM
In Firefox:

I create a form element and set it's value using obj.setAttribute("value")

The element is then appended to the document.

The end user then changes the value in the element.

If I retrieve the value of the element using obj.getAttribute("value") it will retain the value that it was given at the time of creation.

If I retrieve it's value using obj.value it works just fine.

Here is an example of the issue.


Is this as it should be?

Just Curious,


01-26-2007, 08:26 PM
Form elements are special in that typing into the textbox does not actually update the HTML "value" attribute. The DOM property "value" reflects the runtime state of the textbox, while the HTML attribute "value" never changes.

01-26-2007, 09:41 PM
As it would seem, in IE 7 though it does. Just wondering which one is right. The way it is implemented in mozilla seems to have it's advantages.


01-26-2007, 09:55 PM
I believe you get get the inital value in IE7 with


If you need it.


01-29-2007, 04:28 PM
yea... It is sort of inconsistency of the javascript syntax related of the way a HTML element is treated. As an element of the DOM tree (having native attributes)? Or as a classic object (on using a JSON syntax where the objects has properties)? This dual "treatment" is weird, I have noticed...

Keep this thread alive, I might have some examples about the issue to be posted later... I am deeply interested in the subject.