How to explicit reference an attribute?

J

Jens

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
 
R

RobB

Jens said:
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...
 
I

Ivan Marsh

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.
 
J

Jens

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
 
D

Dietmar Meier

Jens said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top