473,396 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Using variables as variables

Hey Everyone,

Lets say I have a variable declared as such:

var newVariable="opener";

How can I then use this variable to access the opener of 'window' ?

Meaning, I dont want to access it as such:

window.opener

but as: window.+newVariable

So it uses the contents of newVariable to access the opener.

I need this because I have a couple of variables which I need to
concat to eachother as a string,
and this string in turn is the variable I need to access from
window.opener.varSomething
where varSomething is the variable that stores the variable I need to
access.

Hope I am clear enough,
Regards Frank

Apr 9 '07 #1
5 1187
Frank wrote:
Hey Everyone,

Lets say I have a variable declared as such:

var newVariable="opener";

How can I then use this variable to access the opener of 'window' ?

Meaning, I dont want to access it as such:

window.opener
newVariable
window.newVariable
window[newVariable]
window["opener"]

All refer to the same object...
But "opener" is a poor choice, it may be confused with the window's
opener property.
Mick

>
but as: window.+newVariable

So it uses the contents of newVariable to access the opener.

I need this because I have a couple of variables which I need to
concat to eachother as a string,
and this string in turn is the variable I need to access from
window.opener.varSomething
where varSomething is the variable that stores the variable I need to
access.

Hope I am clear enough,
Regards Frank
Apr 9 '07 #2
Frank wrote:
Lets say I have a variable declared as such:

var newVariable="opener";

How can I then use this variable to access the opener of 'window' ?

Meaning, I dont want to access it as such:

window.opener

but as: window.+newVariable
Use the bracket notation object[expression] e.g.
window[newVariable]

--

Martin Honnen
http://JavaScript.FAQTs.com/
Apr 9 '07 #3
Lee
Frank said:
>Meaning, I dont want to access it as such:

window.opener

but as: window.+newVariable
window[newVariable]

In addition to the "dot" notation (and other methods) attributes
of objects are also available via "square bracket" notation, as
if the object were an array indexed by string attribute names.
--

Apr 9 '07 #4
On 9 apr, 17:16, Lee <REM0VElbspamt...@cox.netwrote:
Frank said:
Meaning, I dont want to access it as such:
window.opener
but as: window.+newVariable

window[newVariable]

In addition to the "dot" notation (and other methods) attributes
of objects are also available via "square bracket" notation, as
if the object were an array indexed by string attribute names.

--

Thanks everyone, I did not know you can also access it using the
square bracket notation.
Regards,
Frank

Apr 9 '07 #5
In comp.lang.javascript message <11**********************@b75g2000hsg.go
oglegroups.com>, Mon, 9 Apr 2007 14:30:20, Frank <f.********@gmail.com>
posted:
>Thanks everyone, I did not know you can also access it using the
square bracket notation.
Which proves that previous responses ought to have advised you to read
the newsgroup FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Apr 10 '07 #6

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

Similar topics

2
by: Hal Vaughan | last post by:
First, I am aware of both SwingUtilities.invokeLater(), and of using Thread to create a new thread.  These are part of the problem. I want to have something running in the background, while the...
3
by: Guy Robinson | last post by:
I have the code below which parses an expression string and creates tokens. Can anyone suggest the best of error checking for things like: Valid variable only obj.attribute -whitespace allowed...
13
by: Steven Scaife | last post by:
I have decided to re-write the intranet site i created over a year ago. The coding is pretty awful and hard to read cos I made the mistake of not putting comments in or putting crappy comments in...
8
by: Sergio Otoya | last post by:
Hi all, I need to add an input hidden field to an existing form (post). I have tried a couple things like adding the '<INPUT type=hidden name=idSelectedURL value=http://server/documents>' to...
17
by: Davíð Þórisson | last post by:
now in my web I have some global variables to be used in many different subpages, in the old ASP I simply loaded a variables.asp file into memory using the eval() function. Now I'd like to use XML...
13
by: Andy Baxter | last post by:
Can anyone recommend a good online guide to using objects in javascript? The book I bought (DHTML Utopia) suggests using objects to keep the code clean and stop namespace clashes between different...
19
by: Mitesh | last post by:
Hi all, I have the following code: $req = "SELECT * FROM table1"; $res = mysql_query($req); if(!$res) return;
3
accessbunnie
by: accessbunnie | last post by:
Hello Access Users! I am a bit of an Access novice and am currently creating a database and have come up against a huge (for me!) road block. I do not write in Access code and instead, tend to...
0
by: Luis Zarrabeitia | last post by:
Quoting Joe Strout <joe@strout.net>: I'm sure your credentials are bigger than mine. But he is right. A lot of languages have ditched the "concept" of a static variable on a method (how do you...
15
by: r0g | last post by:
Hi There, I know you can use eval to dynamically generate the name of a function you may want to call. Can it (or some equivalent method) also be used to do the same thing for the variables of a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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,...

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.