473,513 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

So simple it is killing me! > dynamic object reference

I thought it would be something like an "eval" but it is not. I want to
refer to an object called "myobject".

I can normally do this:

document.myobject.innerText= "43"

But since I don't know the name of the object, I need something like:

document["myob" + "ject"].innerText= "43"

But it doesn't work. Can anyone help? Thanks,
Mike
Jul 20 '05 #1
7 4084
Nevermind, I found the answer in another thread here:
document.getElementById("myob" + "ject").innerText = "43";

Thanks HikksNotAtHome!

"Mike Hnatt" <do**@gladstone-inc.com> wrote in message
news:vo************@corp.supernews.com...
I thought it would be something like an "eval" but it is not. I want to
refer to an object called "myobject".

I can normally do this:

document.myobject.innerText= "43"

But since I don't know the name of the object, I need something like:

document["myob" + "ject"].innerText= "43"

But it doesn't work. Can anyone help? Thanks,
Mike

Jul 20 '05 #2
In article <vo************@corp.supernews.com>, "Mike Hnatt"
<do**@gladstone-inc.com> writes:
Nevermind, I found the answer in another thread here:
document.getElementById("myob" + "ject").innerText = "43";

Thanks HikksNotAtHome!


Ummm, welcome, whatever I did.
BTW, what did I do?

Not sure why you are breaking the string like that though.

document.getElementById(var1 + var2).innerText = "43";

will give you a reference to what ever var1+var2 evaluates to. Also, innerText
is IE only.

Or is that what you meant?
--
Randy
Jul 20 '05 #3
Hi,

Mike Hnatt wrote:
I thought it would be something like an "eval" but it is not. I want to
refer to an object called "myobject".
Nevermind, I found the answer in another thread here:
document.getElementById("myob" + "ject").innerText = "43";


Note however that not all browsers allow getElementById. An alternative
might be

window[ "myob" + "ject" ]

All global objects are actually stored in the global object. In the case
of the browser, the global object is the Window.

HTH,

Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Jul 20 '05 #4
"Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_SPAM.ch> writes:
Note however that not all browsers allow getElementById. An
alternative might be window[ "myob" + "ject" ]
Far fewer browsers allow for that, and of those only one allow
innerText. Generally, only IE allow for the innerText property (and
Opera 7).

All modern browsers understand getElementById (Mozilla, Opera 6+, IE
5+, etc.).
All global objects are actually stored in the global object. In the
case of the browser, the global object is the Window.


Correct. But named elements are not usually made available as global
variables. Accessing elements as global variables should only be the
last resort, after having tried document.getElementById, document.all
(IE4), and document.layers (Netscape 4).

/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
Lasse Reichstein Nielsen states: "All modern browsers understand
getElementById (Mozilla, Opera 6+, IE 5+, etc.).".I have no argument
with this. However in the US and Canada about one million use the
MSNTV(former WebTV) service. Even the latest 2.8.1 version of this
browser is very outdated in support of both JS and CSS. It does not
support getElementById at all - only document.all. The CSS support is
very strange. It does not support many things in CSS1, such as fancy
borders. However it supports positioning of CSS2 fairly well. Also it
will support some CSS style at the local division level but not at the
global level in the head. The MSNTV service tends to be used by first
time users who tend to either be young people or older adults who have
never used a computer before. The MSNTV developer site has an MSNTV
viewer that can be downloaded to a computer if one wants a fair idea
of how their page might appear on MSNTV. Set top boxes have not grown
much in usage in recent years. Unless MSNTV comes out with both a new
browser and an improved box soon, I think it may slowly fade away.
Jul 20 '05 #6
cw******@yahoo.com (cwdjr) writes:
However in the US and Canada about one million use the MSNTV(former
WebTV) service. Even the latest 2.8.1 version of this browser is
very outdated in support of both JS and CSS. It does not support
getElementById at all - only document.all.
Thank you for that information. I though IE 4 was the only browser to
support document.all and not document.getElementById.

For maximal compatability, I would use a function like

function getElement(id) {
if (document.getElementById) {return document.getElementById(id);}
if (document.all) {return document.all[id];}
if (document.layers) {return document.layers[id];}
return window[id];
}
The CSS support is very strange.

....
Sounds like an early, and slightly mangled, version of IE 4 :)

/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 #7
Thanks all. I used Lasse's maximal compatibility and it works great!
Thanks again,
Mike
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:zn**********@hotpop.com...
cw******@yahoo.com (cwdjr) writes:
However in the US and Canada about one million use the MSNTV(former
WebTV) service. Even the latest 2.8.1 version of this browser is
very outdated in support of both JS and CSS. It does not support
getElementById at all - only document.all.


Thank you for that information. I though IE 4 was the only browser to
support document.all and not document.getElementById.

For maximal compatability, I would use a function like

function getElement(id) {
if (document.getElementById) {return document.getElementById(id);}
if (document.all) {return document.all[id];}
if (document.layers) {return document.layers[id];}
return window[id];
}
The CSS support is very strange.

...
Sounds like an early, and slightly mangled, version of IE 4 :)

/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 #8

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

Similar topics

3
1656
by: Christopher Benson-Manica | last post by:
I need a simple HTML element whose text I can change dynamically. What is it? (it doesn't seem to be <div>, since I can't seem to find what properties a <div> has...) -- Christopher...
16
1999
by: cppaddict | last post by:
Hi, I am deleting some objects created by new in my class destructor, and it is causing my application to error at runtime. The code below compiles ok, and also runs fine if I remove the body...
8
5094
by: Ross A. Finlayson | last post by:
I'm trying to write some C code, but I want to use C++'s std::vector. Indeed, if the code is compiled as C++, I want the container to actually be std::vector, in this case of a collection of value...
3
1312
by: Stephen Gennard | last post by:
Hello, I having a problem dynamically invoking a static method that takes a reference to a SByte*. If I do it directly it works just fine. Anyone any ideas why? I have include a example...
4
2023
by: Tom | last post by:
Hi .Net Professional : In recent , I starting to learn about dynamic call .net object in vb.net. Before, some IT people teach me use the following method and its work !! Dim asm As =...
8
2002
by: George Meng | last post by:
I got a tough question: The backgroud for this question is: I want to design an application works like a engine. After release, we can still customize a form by adding a button, and source code...
17
2433
by: Jason Doucette | last post by:
I am converting a C-style unit into a C++ class. I have an implementation function that was defined in the .cpp file (so it was hidden from the interface that exists in the .h file). It uses a...
30
3473
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
2
5006
by: englishman69 | last post by:
Hello, I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation...
0
7257
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
7535
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...
1
7098
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...
0
7521
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
5682
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,...
1
5084
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...
0
1591
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 ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
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.