How to explicit reference an attribute?

Discussion in 'Javascript' started by Jens, Mar 9, 2005.

  1. Jens

    Jens Guest

    Hi
    I have made a mistake, and have named an input object the same as a form
    attribute, i now want to change with some jscript. I don't want to change
    all my codepages, so i need to address the attribute explicitly.
    Some pseudo code will ilustrate what i did wrong:
    <form name=myForm id=myForm.....>
    <input type=submit name=action id=action....>
    My problem is, that when i try to execute document.myForm.action='xxx.htm' i
    refference the submit object i myForm instead.

    Can anybody please tell me how i reference the action attribute in the form
    object instead?

    Thank you in adwance
    Jens
     
    Jens, Mar 9, 2005
    #1
    1. Advertising

  2. Jens

    RobB Guest

    Jens wrote:
    > Hi
    > I have made a mistake, and have named an input object the same as a

    form
    > attribute, i now want to change with some jscript. I don't want to

    change
    > all my codepages, so i need to address the attribute explicitly.
    > Some pseudo code will ilustrate what i did wrong:
    > <form name=myForm id=myForm.....>
    > <input type=submit name=action id=action....>
    > My problem is, that when i try to execute

    document.myForm.action='xxx.htm' i
    > refference the submit object i myForm instead.
    >
    > Can anybody please tell me how i reference the action attribute in

    the form
    > object instead?
    >
    > Thank you in adwance
    > Jens


    I don't believe there's a workaround for this - in IE, anyway.

    document.getElementById('myForm').get[set]Attribute('action'[,'xxx.htm'])

    ....seems to work elsewhere, but not there. Possibly an issue with the
    form's scope chain that masks the attribute with the element (object).
    IE does some strange things with non-form elements embedded inside a
    form as well.

    Probably best to bite the bullet & fix your files. Could be mistaken...
     
    RobB, Mar 9, 2005
    #2
    1. Advertising

  3. Jens

    Ivan Marsh Guest

    On Wed, 09 Mar 2005 20:29:24 +0100, Jens wrote:

    > Hi
    > I have made a mistake, and have named an input object the same as a form
    > attribute, i now want to change with some jscript. I don't want to
    > change all my codepages, so i need to address the attribute explicitly.
    > Some pseudo code will ilustrate what i did wrong: <form name=myForm
    > id=myForm.....>
    > <input type=submit name=action id=action....> My problem is, that when i
    > try to execute document.myForm.action='xxx.htm' i refference the submit
    > object i myForm instead.
    >
    > Can anybody please tell me how i reference the action attribute in the
    > form object instead?


    Since action is an attribute of a form I'm guessing you can't use "action"
    no matter how you reference it. None the less, you need to change your
    code. That's going to be a fun search and replace.

    --
    Life is short, but wide. -KV
     
    Ivan Marsh, Mar 9, 2005
    #3
  4. Jens

    Jens Guest

    I think i found an ansver myself.
    If referenced like this document.myForm.attributes['action'].value='xxx.htm'
    i get the wantet result. Tested with IE6 and NS7.
    Also, if the input object is named ACTION in uppercase, wich is easy to
    change in my code, it seems the right attribute will be referenced.

    Comments and sugestions are welcome.

    /Jens


    "Jens" <-schroeder.dk> wrote in message
    news:422f4e94$0$21856$...
    > Hi
    > I have made a mistake, and have named an input object the same as a form
    > attribute, i now want to change with some jscript. I don't want to change
    > all my codepages, so i need to address the attribute explicitly.
    > Some pseudo code will ilustrate what i did wrong:
    > <form name=myForm id=myForm.....>
    > <input type=submit name=action id=action....>
    > My problem is, that when i try to execute document.myForm.action='xxx.htm'

    i
    > refference the submit object i myForm instead.
    >
    > Can anybody please tell me how i reference the action attribute in the

    form
    > object instead?
    >
    > Thank you in adwance
    > Jens
    >
    >
     
    Jens, Mar 9, 2005
    #4
  5. Jens wrote:

    > If referenced like this
    > document.myForm.attributes['action'].value='xxx.htm' i get the wantet
    > result. Tested with IE6 and NS7.
    > Also, if the input object is named ACTION in uppercase, wich is easy
    > to change in my code, it seems the right attribute will be referenced.


    The "attributes" collection was introduced in DOM Level 1, so if you
    want to support some old browsers like NN4, and you can easily change
    your code to use an upper case form control's name, you should do so.
    If you don't have to care for old browsers, choose the first variant.

    ciao, dhgm
     
    Dietmar Meier, Mar 9, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jean Stax
    Replies:
    4
    Views:
    460
    lilburne
    Nov 23, 2003
  2. J.T. Conklin
    Replies:
    1
    Views:
    445
    David Hilsee
    Aug 11, 2004
  3. Andy
    Replies:
    5
    Views:
    513
    Shezan Baig
    Jan 30, 2005
  4. Replies:
    1
    Views:
    583
    Salt_Peter
    Dec 25, 2006
  5. Grizlyk
    Replies:
    5
    Views:
    435
    Grizlyk
    Feb 1, 2007
Loading...

Share This Page