/    Sign up×
Community /Pin to ProfileBookmark

js variable keeps coming up ‘undefined’

Greetings colleagues,
I’ve boiled down my code to the essence of the problem; a variable which serves as a parameter to a function keeps coming up as ‘undefined’. The code is quite simple:
….
<head>
<title>Yearly Calendar</title>
<link href=”styles.css” rel=”stylesheet” type=”text/css” />
<link href=”yearly.css” rel=”stylesheet” type=”text/css” />

<script type=”text/javascript”>

function writeMonthCell(calandarDay, currentTime)
{
alert(typeof calendarDay);
var this_DATE=new Date(calendarDay);
document.write(“inside writeMonthCell the date is: ” + this_DATE);

}//end writeMonthCell function

</script>
</head>

<
body>

<div id=”main”>
<h1>Yearly Calendar</h1>
<script type=”text/javascript”>
var thisDate=new Date(“March 25, 2011 14:35:05”);

var thistime=thisDate.getTime();

document.write(“the date is:” + thisDate+”<br />”);
document.write(“the time is:” + thistime+”<br />”);

alert(typeof thisDate);
writeMonthCell(thisDate, thistime);

</script>

</div>
</body>
</html>

in the main body the alert(typeof thisDate) displays ‘object’; but when the function is called, writeMonthCell, inside the function the alert says ‘calendar undefined’ .

I’m perplexed; why is thisDate now undefined as a parameter?

Your comments would be very appreciated!!

captsig

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@Sterling_IsfineSep 17.2010 — 
I'm perplexed; why is thisDate now undefined as a parameter?

Your comments would be very appreciated!!

[/QUOTE]
It isn't undefined, you're alerting an undefined variable and if I saw it so can you.
Copy linkTweet thisAlerts:
@OfekmeisterSep 18.2010 — [CODE]function writeMonthCell([COLOR="Red"]calandar[/COLOR]Day, currentTime)
{
alert(typeof [COLOR="Blue"]calendar[/COLOR]Day);
var this_DATE=new Date(calendarDay);
document.write("inside writeMonthCell the date is: " + this_DATE);

}//end writeMonthCell function
</script>[/CODE]
Copy linkTweet thisAlerts:
@captsigauthorSep 18.2010 — if I take out the line for the alert(typeof calendarDay), then the script still produces an error for the next line saying "calendarDay undefined"
Copy linkTweet thisAlerts:
@Sterling_IsfineSep 18.2010 — if I take out the line for the alert(typeof calendarDay), then the script still produces an error for the next line saying "calendarDay undefined"[/QUOTE]

"You see but you do not observe" - 'Sherlock Holmes' [I]A Scandal in Bohemia[/I]
Copy linkTweet thisAlerts:
@captsigauthorSep 18.2010 — I finally have things moving ahead again; thanks for your consideration just the same.

In the line:function writeMonthCell(calandarDay, currentTime), you normally think of calendarDay and currentTime as a place-holding parameters; I guess this is not so for date objects. Once I made sure that the calling statement had the same param. name, i.e. calendarDay the errors for 'undefined' stopped appearing.

captsig
Copy linkTweet thisAlerts:
@OfekmeisterSep 18.2010 — You spelled calendar "calandar" in the function declaration. That was the only problem.
Copy linkTweet thisAlerts:
@captsigauthorSep 18.2010 — Ofekmeiter!! you're right!! How stupid of me. Amazing how the obvious can escape us.

Thanks for your response.

captsig
×

Success!

Help @captsig spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...