473,587 Members | 2,267 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.myobje ct.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 4090
Nevermind, I found the answer in another thread here:
document.getEle mentById("myob" + "ject").innerTe xt = "43";

Thanks HikksNotAtHome!

"Mike Hnatt" <do**@gladsto ne-inc.com> wrote in message
news:vo******** ****@corp.super news.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.myobje ct.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**@gladsto ne-inc.com> writes:
Nevermind, I found the answer in another thread here:
document.getEl ementById("myob " + "ject").innerTe xt = "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.getEle mentById(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.getEle mentById("myob" + "ject").innerTe xt = "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_S PAM.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.getEle mentById, 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.getEle mentById.

For maximal compatability, I would use a function like

function getElement(id) {
if (document.getEl ementById) {return document.getEle mentById(id);}
if (document.all) {return document.all[id];}
if (document.layer s) {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.getEle mentById.

For maximal compatability, I would use a function like

function getElement(id) {
if (document.getEl ementById) {return document.getEle mentById(id);}
if (document.all) {return document.all[id];}
if (document.layer s) {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
1661
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 Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
16
2009
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 of the destructor. So I think I am somehow using delete incorrectly, but I'm not sure exaclty what I'm doing wrong. I'd apprecitate any...
8
5100
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 types or std::vector<int>. So where I would use an int* and reallocate it from time to time in C, and randomly access it via , then I figure to...
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 below... --
4
2026
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 = .LoadFrom("D:\vb7Project\dynamicCall\prj01\prj01\bin\prj01.dll") Dim ty As Type = asm.GetType("prj01.dbLib")
8
2005
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 for the button. (This is done by the form itself, not by using VS.Net) (button and source code should be a record in database, these information...
17
2454
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 structure that is only needed by the implementation, so it were declared in the .cpp file, as well. Now, when converting this into a class, the...
30
3497
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
5013
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 is this, I have a page which uses multiple postbacks to generate a list of dynamic text boxes with appropriate labels. However, when I do the final...
0
7915
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8205
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
8339
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
6619
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...
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...
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.