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
4 1471
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: - return eval("getDate." + x + "[0]") + "" + eval("getDate." + x + "[day]");
If someone knows of a better solution, please "correct" this.
Your solution works. I just had a syntax error when I wrote first time.
Thank you.
Raja
You're welcome. If I find a better solution, I'll post here.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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;
|
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:
...
|
by: SAL |
last post by:
I am getting the following ERROR in my WebApp on line 30:
Server Error in '/TestWebApp' Application.
--------------------------------------------------------------------------------
Object...
|
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. ...
|
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:
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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...
|
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: 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,...
|
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,...
|
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...
|
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,...
| |