JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2059
Number of posts: 5157

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
about DOM properties Posted by mac_doggie on 23 Nov 2004 at 4:42 AM
Hi,

In Internet explorer you can create your own properties in DOM objects like this:
<form name="myform" myAttribute="MyValue" >
"
"
</form>


You can acces them via JavaScript like this:
alert(document.myform.myAttribute);


but when I use mozilla firefox I get an undefined... Is this a know isue ? Or am I dong something wrong ? Or shouldn't I be creating my own properties... ? I Use them for validation of my forms. I can set an attribute mandatory to true or false in my formfields etc...

hope someone can help me out here...


-mac-
mailto:mac_doggie@hotmail.com
the Netherlands...

Report
Re: about DOM properties Posted by zibadian on 23 Nov 2004 at 5:58 AM
: Hi,
:
: In Internet explorer you can create your own properties in DOM objects like this:
:
: <form name="myform" myAttribute="MyValue" >
: "
: "
: </form>
: 

:
: You can acces them via JavaScript like this:
:
: alert(document.myform.myAttribute);
: 

:
: but when I use mozilla firefox I get an undefined... Is this a know isue ? Or am I dong something wrong ? Or shouldn't I be creating my own properties... ? I Use them for validation of my forms. I can set an attribute mandatory to true or false in my formfields etc...
:
: hope someone can help me out here...
:
:
: -mac-
: mailto:mac_doggie@hotmail.com
: the Netherlands...
:
:
DOM is a technology designed by MS and not very well supported by other non-MS browsers. This is known issue and due MS's policies will probably not be resolved very quickly.
There are two possible solutions: warn users about the coding and suggest that they use IE to explore your page; or find a way around it, possibly by defining your attributes in a 2D-array which accompanies your page.
Report
Re: about DOM properties Posted by Weirdofreak on 23 Nov 2004 at 1:50 PM
You should never make your page require a particular browser. I don't even have IE, so any page which only works in it I can't view.

The problem is that Mozilla/Firefox doesn't use names as child properties of the document. I'd assume that's according to the W3C standard, and imagine the problems if you named an element after a built-in property. You could loop through every element with document.getElementsByTagName(*) and find one with the name attribute set to whatever, or you can use document.getElementById('id') and give them IDs rather than names (which also prevents giving two elements the same name). You could also try document.getElementsByName('name'), but I don't know if IE or Opera support it. Note that it should return a list of elements in case you do share them, so you'll have to do document.getElementsByName('myform')[0] to access the element named myform.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.