473,587 Members | 2,579 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.form s[1].elements.lengt h; i++ )
{
if ( document.forms[1].elements[i].name == myfield )
{
document.forms[1].elements[i].class = "newstylesheetf ormat";
}
}
}

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.form s[1].elements.lengt h; i++ )
{
for ( j=0; j<document.form s[1].elements[i].properties.len gth; i++ )

{
alert(document. forms[1].elements[i].properties.nam e);
}
}
}
Jul 20 '05 #1
4 5470
Michael Hill <hi****@ram.lmt as.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.form s[1].elements[i].attributes.len gth; 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.form s[1].elements.lengt h; i++ )
{
if ( document.forms[1].elements[i].name == myfield )
{
for ( j=0; j<document.form s[1].elements[i].attributes.len gth; 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.lmt as.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.form s[1].elements[i].attributes.len gth; 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.lmt as.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.form s[1].elements.lengt h; i++ )
{
if ( document.forms[1].elements[i].name == myfield )
{
for ( j=0; j<document.form s[1].elements[i].attributes.len gth; 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.named Item(myfield).c lassName = "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.named Item(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
2774
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 right-click on the control (say a combo box) and select "View Code" it seems to take me back to the last code I was viewing. I would like to go to...
3
5211
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 other things, this package has classes VectorI (and MatrixI) and I am having difficulty instantiating variables of these classes. I begin with...
4
3081
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 the recordset to loop thru the recordset, update values from the recordset and then update the database by passing parmeters to another stored...
1
1164
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 right-click on the control, let's say a combo box, and select "View Code" it seems to take me back to the last code I was viewing. I would like to...
162
14781
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 choice questions.etc.. I'll be indebted to everyone.. Thanks in advance.. regards vasant shetty Bangalore
4
2500
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 cross-posting. I am trying to build a "checklist", where a user can navigate to an ASP page on the intranet which shows a list of "questions" that the...
275
12170
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
1925
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 object in the points variable. class Blob: def __init__(self, points=): self._points = points
8
3044
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 databases (partly because I already had learnt C/C++ and I feel that programming is a lot easier that DBMS). Nevertheless, I must learn at least one DBMS as...
0
8206
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6621
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5713
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.