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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts

    NS7 doesn't accpet fancy attributes for different elements, what can I do?

    Hi, look at this code:
    Code:
    <body>
    <textarea id="whatever" usefarsi="true"></textarea>
    <script>
    alert(document.getElementById("whatever").usefarsi);
    </script>
    It easily works in IE, but as I tested it in NS7 it doesn't work. I really need this functionality and my program fully depends on it, what can I do to make it NS compatible too? Or should I forget about it?!

  • #2
    Regular Coder Skyzyx's Avatar
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It'll work if you do it the right way instead of the Internet Explorer way.

    Code:
    <body>
    <textarea id="whatever" usefarsi="true"></textarea>
    <script>
    alert(document.getElementById("whatever").getAttribute("usefarsi"));
    </script>
    Last edited by Skyzyx; 04-02-2003 at 08:16 PM.

    Creator of SimplePie and Tarzan AWS, co-founder of WarpShare, co-built the Y! Messenger website, usability-focused, and an INFJ personality.

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    <http://bugzilla.mozilla.org/show_bug.cgi?id=198643>
    Only standard attributes as specified in the DOM ECMAScript bindings are reachable in the element.attributeName way. In earlier versions (about version 0.8, 0.9.0) they didn't have ANY way to reach non-standard attributes.
    Last edited by liorean; 04-02-2003 at 08:33 PM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the help, it's completely resolved now!

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Something else:

    if I have this code:
    Code:
    <input id="test" type="text" language="Farsi">
    then I have to read the language attribute like this:

    Code:
    document.getElementById("test").getAttribute("Farsi");
    But if I make the attribute through a script, then I don't need to use getAttribute:
    Code:
    <input id="test" type="text">
    <script>
    document.getElementById("test").language = "Farsi";
    alert(document.getElementById("test").language);
    </script>
    Ok? So, what if I wana put an array of objects into an attribute? Let's say I have an array like:
    Code:
    b = new Array( 1, 2, 3, 4 );
    Now if I put it inside the language attribute by setAttribute, and then I wana get it back by getAttribute, it only returns a string back, means language[1] = ",", because it looks at it as a string and return the comma after 1.

    So, the only way that's left is not using setAttribute and getAttribute and just adding it normally:
    Code:
    b = new Array( 1, 2, 3, 4 );
    document.getElementById("test").language = b;
    alert(document.getElementById("test").language);
    It's the only way that I found out, do you think that it's standard in different browsers? Also my program doesn't work in some cases and if your answer is no, then I think this is the only buggy part, coz I couldn't find anything wrong with my poor progie!
    Last edited by ConfusedOfLife; 04-03-2003 at 12:23 PM.

  • #6
    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
    I think you are missing something. Let's say we have this:

    var element = document.getElementById('something');

    element.mythingy = true;

    The node that element is referencing does not have a mythingy attribute, even after this. The Node instance representing it in memory does has a mythingy property however.

    Now, say we did:
    element.setAttribute("mythingy", "true");

    Instead. element.mythingy is undefined because there is no mythingy property of the object, just an attribute on the HTML element itself that we modifed.

    So, one might ask howcome we can do:

    element.className = 'somethingnew'

    then. The className property has a setter that updates the class attribute on the element itself, and the className getter returns the value of that attribute.

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, let's see if I could get it!

    You say if I have:

    element = document.getElementById("something");

    and I define element.thingie = 'oopse', then the following equation is wrong:
    Code:
    document.getElementById("something").thingie = 'oopse';
    right? The first thing defines a property that is NOT the attribute that I want.

    Ok, thanks. I somehow tried it in a dummy script and I was aware of it. And because I can't write those setters and getters you talked about ( I just know they make my job easier by the example that you brought, nothing else! ), I conclude that I have to write both of these lines to reach exactly what I want:

    Code:
    element.thingie = 'oopse';
    document.getElementById("something").setAttribute("thingie", "oopse");
    Right? If it's true, then what should I do with all those big loops in my program?! You know, I'm getting all the input/textareas in my page by document.getElementsByTagName and putting them inside a gigantic array. Then I itterate through the array changing/adding/removing things. So, each element of that array refers to one of the inputs/textareas in my page. Do you mean that for adding any new attribute ( not property ) to one of those tags, I have to call document.getElementsByTagName again? How would I find it?!

    Edit: I know that I have to use setAttribute instead of adding a property to each element of that array I talked about, but I really need the functionality of putting an array in one of the attributes. If I have array b ( look at my previous post ) and I add it to one of the properties by setAttribute, it doesn't put the array there, and instead it puts a string over there. You know, I have another array of objects which I wana put inside one of my properties ( callers property ) and then whenever the element is clicked on for example, I wana get that property ( that i expect it to be an array of objects ) and then easily refer to each object by myElement.callers[ i ] . If I use setAttribute and then getAttribute to get the array, what I get is NOT an array, it's a string. If my original array was for example an array of numbers then it's no problem, I could split it. But I have an array of objects! How can I get back my objects?! I don't know, was I clear enough?
    Last edited by ConfusedOfLife; 04-03-2003 at 10:08 PM.


  •  

    Posting Permissions

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