473,513 Members | 11,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

object questions and difficulty

This a valid call:
document.myform.elements['myelement']
so is this:
document.forms[0].elements[1]
but not this:
document.forms[0].elements['myelement']

So, I have to iterate through the elements to find my field and make a
change to the element properties

myfield = "myelement";
for ( i=0; i<document.forms[1].elements.length; i++ )
{
if ( document.forms[1].elements[i].name == myfield )
{
document.forms[1].elements[i].class = "newstylesheetformat";
}
}
}

Why is the document.forms[1].elements[i].class property not accessible
using this method even though I specified it in the form?

If I wanted to iterate through the properties of the elements how would
I do this, like this?

for ( i=0; i<document.forms[1].elements.length; i++ )
{
for ( j=0; j<document.forms[1].elements[i].properties.length; i++ )

{
alert(document.forms[1].elements[i].properties.name);
}
}
}
Jul 20 '05 #1
4 5467
Michael Hill <hi****@ram.lmtas.lmco.com> writes:
Why is the document.forms[1].elements[i].class property not accessible
using this method even though I specified it in the form?
Probably because it should be
document.forms[1].elements[i].className
The renaming is most likely because "class" is a restricted word or keyword
in many languages (including Javascript).
If I wanted to iterate through the properties of the elements how would
I do this, like this?


What do you mean by "properties"?

In Javascript, an object has properties. You iterate through (some of) them
with
for (var propName in objRef) { ... propName ... }

If you mean the attributes of the html tag, it ".attributs" that you need
to run through:
for ( j=0; j<document.forms[1].elements[i].attributes.length; i++ )

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Lee
Michael Hill said:

This a valid call:
document.myform.elements['myelement']
so is this:
document.forms[0].elements[1]
but not this:
document.forms[0].elements['myelement']


In what browser is that not valid? It works in Netscape and IE.

Jul 20 '05 #3
Lasse,

Thanks for helping. So you are saying everytime I want to change the class of
my input text item I have to do this?

for ( i=0; i<document.forms[1].elements.length; i++ )
{
if ( document.forms[1].elements[i].name == myfield )
{
for ( j=0; j<document.forms[1].elements[i].attributes.length; j++ )
{
if ( document.forms[1].elements[i].attributes[j].name == "class" )
{
document.forms[1].elements[i].attributes[j].value = "grey";
break;
}
}
}
}

Lasse Reichstein Nielsen wrote:
Michael Hill <hi****@ram.lmtas.lmco.com> writes:
Why is the document.forms[1].elements[i].class property not accessible
using this method even though I specified it in the form?


Probably because it should be
document.forms[1].elements[i].className
The renaming is most likely because "class" is a restricted word or keyword
in many languages (including Javascript).
If I wanted to iterate through the properties of the elements how would
I do this, like this?


What do you mean by "properties"?

In Javascript, an object has properties. You iterate through (some of) them
with
for (var propName in objRef) { ... propName ... }

If you mean the attributes of the html tag, it ".attributs" that you need
to run through:
for ( j=0; j<document.forms[1].elements[i].attributes.length; i++ )

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'


Jul 20 '05 #4
Michael Hill <hi****@ram.lmtas.lmco.com> writes:
So you are saying everytime I want to change the class of my input
text item I have to do this?

for ( i=0; i<document.forms[1].elements.length; i++ )
{
if ( document.forms[1].elements[i].name == myfield )
{
for ( j=0; j<document.forms[1].elements[i].attributes.length; j++ )
{
if ( document.forms[1].elements[i].attributes[j].name == "class" )
{
document.forms[1].elements[i].attributes[j].value = "grey";
break;
}
}
}
}


That shouldn't be necessary.

document.forms[1].elements.namedItem(myfield).className = "gray";

If you insist on changing the HTML attribute value (some browsers don't
link className and the class Attribute element):

var elem = document.forms[1].elements.namedItem(myField);
elem.attributes.getNamedItem("class").value = "gray";

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2767
by: Jmar | last post by:
Having spent many years working with VB 4.0 I've recently purchased VB.net. At this early point I have two questions. 1) How can I QUICKLY view the code associated with a specific control? If I...
3
5205
by: Kavindra Malik | last post by:
I am learning to use a shareware package for statistics and optimization- drasys.or.* ( found at http://opsresearch.com/OR-Objects/) to get to use some stats and operations research objects. Among...
4
3073
by: Tom | last post by:
I want to open a recordset object on an .asp page. When I open the recordset I would like to use a stored procedure that expects a parameter to be passed for the stored procedure. I will then use...
1
1154
by: Jmar | last post by:
Having spent many years working with VB 4.0 I've recently purchased VB.net. At this early point I have two questions. 1) How can I QUICKLY view the code associated with a specific control? If I...
162
14706
by: techievasant | last post by:
hello everyone, Iam vasant from India.. I have a test+interview on C /C++ in the coming month so plz help me by giving some resources of FAQS, interview questions, tracky questions, multiple...
4
2494
by: Drew | last post by:
I posted this to the asp.db group, but it doesn't look like there is much activity on there, also I noticed that there are a bunch of posts on here pertaining to database and asp. Sorry for...
275
12039
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
35
1906
by: Rick Giuly | last post by:
Hello All, Why is python designed so that b and c (according to code below) actually share the same list object? It seems more natural to me that each object would be created with a new list...
8
3035
AmberJain
by: AmberJain | last post by:
Hello, My new semester has started and I have a subject named DBMS (Database Management System). This is the first time I'm studying databases and so I'm not feeling very enthusiastic about...
0
7254
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.