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


Groups > comp.lang.javascript > #16054 > unrolled thread

referencing variable name for object in an array, receiving TypeError when using to set property of object

Started byQuaye Trimble <qtrimble@gmail.com>
First post2012-09-20 10:51 -0700
Last post2012-10-10 05:28 -0700
Articles 3 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  referencing variable name for object in an array, receiving TypeError when using to set property of object Quaye Trimble <qtrimble@gmail.com> - 2012-09-20 10:51 -0700
    Re: referencing variable name for object in an array, receiving TypeError when using to set property of object JJ <jaejunks_at@_googlemail_dot._com> - 2012-09-20 22:56 +0000
      Re: referencing variable name for object in an array, receiving TypeError when using to set property of object Quaye Trimble <qtrimble@gmail.com> - 2012-10-10 05:28 -0700

#16054 — referencing variable name for object in an array, receiving TypeError when using to set property of object

FromQuaye Trimble <qtrimble@gmail.com>
Date2012-09-20 10:51 -0700
Subjectreferencing variable name for object in an array, receiving TypeError when using to set property of object
Message-ID<5f8cd44c-a554-42b4-bde5-5e099bdce516@googlegroups.com>
This would probably be better described if I give you the link so you can follow along.

https://bccmws.coastal.edu/buoydata/buoyobs1.html

The function initChart contains a single argument which defines the time period of data to display .  The function gets the data and configures some of the chart options.  Most of the chart options are already defined in a separate js file.  OK, so within this function, I’m referencing a global object called dataArr which stores some configuration information for querying the data and defining some additional chart options.  You can see how I’m constructing the object on line 185 if you are using Firebug or something similar.  If data is returned I’m calling the function setChart and passing a bunch of arguments into it.  The first argument contains the variable name of one of the external chart options object.  Using the Firebug console, the output is correct but I’m getting a TypeError.  It’s as if the variable output isn’t being used to define the chart option variable name but it’s like it wants the variable name to be a completely different object.

I’m not trained in JavaScript (or any programming language for that matter) so I’m probably doing something that isn’t allowed.

Let me know if I need to clarify anything and thanks for your willingness to help me.

Quaye

[toc] | [next] | [standalone]


#16063

FromJJ <jaejunks_at@_googlemail_dot._com>
Date2012-09-20 22:56 +0000
Message-ID<XnsA0D53CE8D69C8jaejunksgooglemailco@0.0.0.89>
In reply to#16054
Quaye Trimble <qtrimble@gmail.com> wrote:

> This would probably be better described if I give you the link so you
> can follow along. 
> 
> https://bccmws.coastal.edu/buoydata/buoyobs1.html
> 
> The function initChart contains a single argument which defines the
> time period of data to display .  The function gets the data and
> configures some of the chart options.  Most of the chart options are
> already defined in a separate js file.  OK, so within this function,
> I'm referencing a global object called dataArr which stores some
> configuration information for querying the data and defining some
> additional chart options.  You can see how I'm constructing the object
> on line 185 if you are using Firebug or something similar.  If data is
> returned I'm calling the function setChart and passing a bunch of
> arguments into it.  The first argument contains the variable name of
> one of the external chart options object.  Using the Firebug console,
> the output is correct but I'm getting a TypeError.  It's as if the
> variable output isn't being used to define the chart option variable
> name but it's like it wants the variable name to be a completely
> different object. 
> 
> I'm not trained in JavaScript (or any programming language for that
> matter) so I'm probably doing something that isn't allowed. 
> 
> Let me know if I need to clarify anything and thanks for your
> willingness to help me. 
> 
> Quaye

The "setChart" function expects its "theChartOptions" parameter to be an 
object. However, in "initChar" function where it calls "setChart", it 
passes a string as the "theChartOptions" parameter:

setChart(dataArr[i].chartoptions,theDataObj,dataArr
[i].cname,type,chartNo);


Since "setChart" expects it to be one of the "optionsNN" object in the 
global context, then the call to "setChart" can be fixed like this:

setChart(window[dataArr[i].chartoptions],theDataObj,dataArr
[i].cname,type,chartNo);

[toc] | [prev] | [next] | [standalone]


#16528

FromQuaye Trimble <qtrimble@gmail.com>
Date2012-10-10 05:28 -0700
Message-ID<3e4a3a59-6d3c-4a2f-a361-0de6b9433de4@googlegroups.com>
In reply to#16063
> 
> 
> 
> > This would probably be better described if I give you the link so you
> 
> > can follow along. 
> 
> > 
> 
> > https://bccmws.coastal.edu/buoydata/buoyobs1.html
> 
> > 
> 
> > The function initChart contains a single argument which defines the
> 
> > time period of data to display .  The function gets the data and
> 
> > configures some of the chart options.  Most of the chart options are
> 
> > already defined in a separate js file.  OK, so within this function,
> 
> > I'm referencing a global object called dataArr which stores some
> 
> > configuration information for querying the data and defining some
> 
> > additional chart options.  You can see how I'm constructing the object
> 
> > on line 185 if you are using Firebug or something similar.  If data is
> 
> > returned I'm calling the function setChart and passing a bunch of
> 
> > arguments into it.  The first argument contains the variable name of
> 
> > one of the external chart options object.  Using the Firebug console,
> 
> > the output is correct but I'm getting a TypeError.  It's as if the
> 
> > variable output isn't being used to define the chart option variable
> 
> > name but it's like it wants the variable name to be a completely
> 
> > different object. 
> 
> > 
> 
> > I'm not trained in JavaScript (or any programming language for that
> 
> > matter) so I'm probably doing something that isn't allowed. 
> 
> > 
> 
> > Let me know if I need to clarify anything and thanks for your
> 
> > willingness to help me. 
> 
> > 
> 
> > Quaye
> 
> 
> 
> The "setChart" function expects its "theChartOptions" parameter to be an 
> 
> object. However, in "initChar" function where it calls "setChart", it 
> 
> passes a string as the "theChartOptions" parameter:
> 
> 
> 
> setChart(dataArr[i].chartoptions,theDataObj,dataArr
> 
> [i].cname,type,chartNo);
> 
> 
> 
> 
> 
> Since "setChart" expects it to be one of the "optionsNN" object in the 
> 
> global context, then the call to "setChart" can be fixed like this:
> 
> 
> 
> setChart(window[dataArr[i].chartoptions],theDataObj,dataArr
> 
> [i].cname,type,chartNo);

JJ - your solution works perfectly and I learned something extremely valuable.  Thank you!

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web