This is a bit tricky to describe, but here goes. Any help
appreciated. John
I declare multiple variables halfway down the page. The number
between "mech" and "Num" is generated dynamically in the XSL. Later
on I need to reference that variable in a function, but I need to
build the variable name in script. How do I convert it from a string
reference to a ref to the global variable?
function changePreference(pos,mt){
//mt does not reference mech2Num, I need it to.
}
changePreference(2,'my' + pos + 'Num');
var mech1Num=1|2|3|4|5|6;
var mech2Num=1|2|3|4|5|6;
var mech3Num=1|2|3|4|5|6; 7 1970
johkar wrote: This is a bit tricky to describe, but here goes. Any help appreciated. John
I declare multiple variables halfway down the page. The number between "mech" and "Num" is generated dynamically in the XSL. Later on I need to reference that variable in a function, but I need to build the variable name in script. How do I convert it from a string reference to a ref to the global variable?
function changePreference(pos,mt){ //mt does not reference mech2Num, I need it to. } changePreference(2,'my' + pos + 'Num');
var mech1Num=1|2|3|4|5|6; var mech2Num=1|2|3|4|5|6; var mech3Num=1|2|3|4|5|6;
So you want "mech" + # + "Num" as a dynamic variable name? Simple:
window["mech" + # + "Num"]
Will give you a reference to it.
--
Randy
Randy Webb <Hi************@aol.com> wrote in message news:<7p********************@comcast.com>... johkar wrote:
This is a bit tricky to describe, but here goes. Any help appreciated. John
I declare multiple variables halfway down the page. The number between "mech" and "Num" is generated dynamically in the XSL. Later on I need to reference that variable in a function, but I need to build the variable name in script. How do I convert it from a string reference to a ref to the global variable?
function changePreference(pos,mt){ //mt does not reference mech2Num, I need it to. } changePreference(2,'my' + pos + 'Num');
var mech1Num=1|2|3|4|5|6; var mech2Num=1|2|3|4|5|6; var mech3Num=1|2|3|4|5|6;
So you want "mech" + # + "Num" as a dynamic variable name? Simple:
window["mech" + # + "Num"]
Will give you a reference to it.
Thanks, I hadn't come across that method, I ended up using eval(). I
need to look up which is supported by more browsers.
John
On 2 Nov 2004 03:55:41 -0800, johkar <no********@msn.com> wrote: Randy Webb <Hi************@aol.com> wrote in message news:<7p********************@comcast.com>...
[snip] window["mech" + # + "Num"]
Will give you a reference to it.
Thanks, I hadn't come across that method,
It's given a lot of detail in the FAQ notes
(<URL:http://www.jibbering.com/faq/faq_notes/square_brackets.html>).
I ended up using eval().
Don't. The eval function is slower and tends to lead to errors and bad
practice. Most people start seeing it as some kind of magic-wielding,
catch-all function that will accomplish whatever the author wants. It
actually has a specific use that most people will *never* need.
I need to look up which is supported by more browsers.
Both just as well, but bracket notation is *much* preferred.
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Michael Winter wrote: johkar wrote:
<snip> I need to look up which is supported by more browsers.
Both just as well, but bracket notation is *much* preferred.
They are not quite equally supported. ECMA 327 ('ECMAScript Compact
Profile') allows implementations for small devices to have an - eval -
function that does no more than throw exceptions, and the AvantGo 3
browser (for PDAs, and getting on a bit now) did not implement - eval -
at all.
Richard.
On Tue, 2 Nov 2004 20:58:21 -0000, Richard Cornford
<Ri*****@litotes.demon.co.uk> wrote: Michael Winter wrote:
[snip] Both [eval and bracket notation work] just as well, but bracket notation is *much* preferred.
They are not quite equally supported.
[snip]
I didn't know that, but then again, I've never read the Compact Profile,
nor have I ever used AvantGo.
Thanks for the correction, particularly as it serves to reaffirm the
latter part of the sentence.
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
JRS: In article <cm*******************@news.demon.co.uk>, dated Tue, 2
Nov 2004 20:58:21, seen in news:comp.lang.javascript, Richard Cornford
<Ri*****@litotes.demon.co.uk> posted : ECMA 327 ('ECMAScript Compact Profile')
<FAQENTRY> ECMA 327
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: hello smith |
last post by:
I have a lot of functions that add values to an array. They alos update
a global variable of type int. Currently, I use a global variable to
hold this array. All functions access this array...
|
by: man |
last post by:
can any one please tell me what is the diff between pointer and
reference.....and which one is better to use ....and why???????
|
by: Pierre |
last post by:
Hello,
In an aspx page (mypage.aspx) from a web projet,
I would like to get the value of a variable of the projet that is declared
as public in a module.
The variable can be called from...
|
by: David W. Fenton |
last post by:
I think at various times we've all encountered this problem:
A subform is on a main form. From the code of the main form we refer
to some property of/control on the child form thus:
...
|
by: John Henry |
last post by:
Hi list,
Just to make sure I understand this.
Since there is no "pointer" type in Python, I like to know how I do
that.
For instance, if I do:
...some_huge_list is a huge list...
|
by: Jeff Blaine |
last post by:
We have a GCC in /usr/rcf that was not built with --disable-shared.
As such, there is a /usr/rcf/lib/libgcc_s.so.
We also have a (preferred) GCC in /afs/rcf/lang/gcc/current that
was built with...
|
by: ravi |
last post by:
Hi,
i am a c++ programmer,
now i want to learn programming in c also.
so can anybody explain me the difference b/w call by reference and
call by
pointer (with example if possible).
|
by: lisp9000 |
last post by:
I've read that C allows two ways to pass information between
functions:
o Pass by Value
o Pass by Reference
I was talking to some C programmers and they told me there is no such
thing as...
|
by: Bryan Parkoff |
last post by:
I write my large project in C++ source code. My C++ source code
contains approximate four thousand small functions. Most of them are
inline. I define variables and functions in the global scope....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |