Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #37201

Re: Create a string dynamically to reference a property of an object?

Newsgroups comp.lang.javascript
Date 2019-09-10 13:04 -0700
References <aba8a905-8515-4be8-9e03-040f60d109e5@googlegroups.com> <ql8vb5$iqr$1@gioia.aioe.org>
Message-ID <d982f5c8-87f9-4fd7-a03e-3f18bdfcb718@googlegroups.com> (permalink)
Subject Re: Create a string dynamically to reference a property of an object?
From Julio Di Egidio <julio@diegidio.name>

Show all headers | View raw


On Tuesday, 10 September 2019 21:59:40 UTC+2, R.Wieser  wrote:
> Jonas,
> 
> > varString="document.getElementById.('inBox"+x+"').checked";
> 
> Remove the "." just infront of the "(" and try again.
> 
> Hint: When something doesn't work /go back to the simpelest form you know/ -
> in this case trying to execute it directly, and with any additions like
> dynamic ID names:
> 
> console.log("***"+ document.getElementById.('inBox0').checked );
> 
> The above wil fail too, due to that extra ".".  But with a bit of luck (and
> the right tools, which you already seem to use) you will get a lot more info
> about /what/ is going wrong, and can repair it yourself.
> 
> And by the way:  I hope you do realize that the element id you are using
> itself is, after you create that string, not dynamic but hardcoded.
> 
> Ackk .. I just remembered something ...
> 
> And #&$&*^$ @ !!
> 
> Forget that.   I just realized that your explanation was inprecise enough to
> make me think your "object property references" was referring to the
> ".checked" part.   Looking at your previous (differently named, so a bit of
> a gamble) post thats not quite likely.    Give yourself a "well done" slap
> on the shoulder, you just made me waste my time. :-(
> 
> And that also means that if that element id is the /only/ thing thats
> dynamic you do not even need to go thru storing it into a variable and than
> eval-ing it.    It will work perfectly whe you use it directly:
> 
> x=1
> var myVar = document.getElementById('inBox'"+x+"').checked;
> 
> So much for not first trying the simpelest approach first, eh ? <whistle>
> :-)

So much for not even getting the quotes right.

They always come in pairs...

*Plonk*

Julio

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Create a string dynamically to reference a property of an object? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-09-10 11:41 -0700
  Re: Create a string dynamically to reference a property of an object? Julio Di Egidio <julio@diegidio.name> - 2019-09-10 12:38 -0700
    Re: Create a string dynamically to reference a property of an object? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-09-10 14:02 -0700
    Re: Create a string dynamically to reference a property of an object? dr.j.r.stockton@gmail.com - 2019-09-11 12:58 -0700
  Re: Create a string dynamically to reference a property of an object? "R.Wieser" <address@not.available> - 2019-09-10 21:59 +0200
    Re: Create a string dynamically to reference a property of an object? Julio Di Egidio <julio@diegidio.name> - 2019-09-10 13:04 -0700
      Re: Create a string dynamically to reference a property of an object? "R.Wieser" <address@not.available> - 2019-09-11 09:33 +0200
        Re: Create a string dynamically to reference a property of an object? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-09-11 00:52 -0700
          Re: Create a string dynamically to reference a property of an object? "R.Wieser" <address@not.available> - 2019-09-11 10:11 +0200
            Re: Create a string dynamically to reference a property of an object? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-09-11 02:09 -0700
              Re: Create a string dynamically to reference a property of an object? "R.Wieser" <address@not.available> - 2019-09-11 13:59 +0200
        Re: Create a string dynamically to reference a property of an object? Julio Di Egidio <julio@diegidio.name> - 2019-09-11 02:11 -0700
          Re: Create a string dynamically to reference a property of an object? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-09-11 03:48 -0700
          Re: Create a string dynamically to reference a property of an object? "R.Wieser" <address@not.available> - 2019-09-11 13:48 +0200

csiph-web