473,399 Members | 3,919 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,399 software developers and data experts.

Error: null or not an object - how to reference object dynamically

2
Hi everybody
What is wrong with the following code?

function Test(month, day) {
var months = ["","Jan", "Feb", "Mar", "...", "Nov", "Dec"];
var getDate = {
"Jan":["January: ","1"],
"Feb":["February: ", "1","2", "...","29"]}

var x = months[month];
return getDate.x[0] + getDate.x[day];
//If I change getDate.x[day] to getDate.Feb[day], then it works. But I need it dynamically
}

alert(Test(2, 1))
I am getting error "'x' is null or not an object".
If I change getDate.x[day] to getDate.Feb[day], then it works.
But I need it dynamically

Thanks in advance
Raja
Mar 5 '07 #1
4 1471
acoder
16,027 Expert Mod 8TB
Welcome Raja to The Scripts.

I know eval is evil and shouldn't be used, but, at the moment, I can only think of this solution:
Expand|Select|Wrap|Line Numbers
  1. return eval("getDate." + x + "[0]") + "" + eval("getDate." + x + "[day]");
If someone knows of a better solution, please "correct" this.
Mar 5 '07 #2
madhra
2
Your solution works. I just had a syntax error when I wrote first time.
Thank you.

Raja
Mar 5 '07 #3
acoder
16,027 Expert Mod 8TB
You're welcome. If I find a better solution, I'll post here.
Mar 5 '07 #4
acoder
16,027 Expert Mod 8TB
Changed title.
Mar 7 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: CHRIS | last post by:
Isn't it always the case that as soon as you post, you solve the problem? Apparently, adding an extra "space" to a blank line in my web.config file solved this problem. I would be angry that...
3
by: Adriano | last post by:
Hello, when I try to print something, either DataGrid or from Crystal Report viever the folowing error message appears and cancels printing: Object reference not set to an instance of an...
2
by: kens | last post by:
I've found some odd behavior in dynamically loaded user controls under ASP.NET 2.0. Specifically, if I load a control dynamically, in the "Page_Load" event, the code-behind for the user control is...
12
by: Joe | last post by:
I might be overworked so please excuse this stupid question... Say I do the following: DataTable table = new DataTable(); myDataAdaptor.Fill(table); dataGrid1.DataSource = table;
1
by: accyboy1981 | last post by:
Hi, I've create a web applicatation the create an xml document dynamically. Now that is does this I would like to add a stylesheet to the xml document. I'm using the following code: ...
3
by: SAL | last post by:
I am getting the following ERROR in my WebApp on line 30: Server Error in '/TestWebApp' Application. -------------------------------------------------------------------------------- Object...
2
by: arun1985 | last post by:
In the project i am using i am having the following code and when i upload it to the server.Its givig me the following error in the global.cs file. Server Error in '/' Application. ...
11
by: LayneMitch via WebmasterKB.com | last post by:
Hello. This is a reference file from a book I read in which the core subject is the use of 'event listeners'. I'm trying to load the file in Firefox and it's giving me an error message: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.