Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts

    Behavior of getAttribute("value")

    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.

    http://dev.rateprice.com/fftest.asp

    Is this as it should be?

    Just Curious,

    Basscyst
    Last edited by Basscyst; 01-26-2007 at 08:55 PM.
    Helping to build a bigger box. - Adam Matthews

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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.

  • #3
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    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.

    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #4
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I believe you get get the inital value in IE7 with

    obj.defaultValue

    If you need it.

    david_kw

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •