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

04-02-2003, 08:32 PM
Hi, look at this code:

<textarea id="whatever" usefarsi="true"></textarea>

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?!

04-02-2003, 08:46 PM
It'll work if you do it the right way instead of the Internet Explorer way.

<textarea id="whatever" usefarsi="true"></textarea>

04-02-2003, 09:13 PM
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.

04-02-2003, 09:58 PM
Thanks for the help, it's completely resolved now!

04-03-2003, 01:21 PM
Something else:

if I have this code:

<input id="test" type="text" language="Farsi">

then I have to read the language attribute like this:


But if I make the attribute through a script, then I don't need to use getAttribute:

<input id="test" type="text">
document.getElementById("test").language = "Farsi";

Ok? So, what if I wana put an array of objects into an attribute? Let's say I have an array like:

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:

b = new Array( 1, 2, 3, 4 );
document.getElementById("test").language = b;

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!

04-03-2003, 07:26 PM
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.

04-03-2003, 10:43 PM
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:

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:

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?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum