In article <>,
Joost Diepenmaat <> wrote:
> Tim Streater <> writes:
>
> > This is partially clear 
> >
> > What I need is the equivalent of:
> >
> > var _global = this;
> > var answer = 42
> >
> > function foo (ref)
> > {
> > alert (ref.value);
> > }
> >
> > var myRef = _global.answer; // I know js doesn't do this 
>
> But that works.
>
> > foo (myRef);
> >
> >
> > but perhaps this is not possible. Meanwhile I'll keep reading what you
> > wrote and using as a reference for searching the web.
>
> Just replace
>
> alert (ref.value)
>
> with
>
> alert(ref);
<grin>
OK, I'm not being clear. Let me give an example from my actual
situation, where I'm trying to keep the code simple. In an onChange
function, I've got document objects to work on, and variables to manage.
In the following code fragment, I can get a reference to the forms
object and I have "invented" a ref() function that gives me a reference
to a variable, in order to illustrate what I would *like* to be able to
do. Clearly I can get round this with extra tests but then it all looks
very clumsy.
if (condition1)
{
docRef = document.forms["form1"].mySel_a; // maybe several of these
vblRef = ref (top.myVbl_a); // I would like to get a reference
}
else {
docRef = document.forms["form1"].mySel_b;
vblRef = ref (top.myVbl_b);
}
if (condition2)
{
docRef.disabled = true;
vblRef.value = 15; // some value
}
else {
docRef.disabled = false;
vblRef.value = 27; // some other value;
}
(condition1 and condition2 are unrelated)