Check members of object
- Details
- Category: JavaScript
- Published on Thursday, 12 May 2011 12:51
- Hits: 148
function dumpProps(obj, parent) {
// Go through all the properties of the passed-in object
for (var i in obj) {
// if a parent (2nd parameter) was passed in, then use that to
// build the message. Message includes i (the object's property name)
// then the object's property value on a new line
if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
// Display the message. If the user clicks "OK", then continue. If they
// click "CANCEL" then quit this level of recursion
if (!confirm(msg)) { return; }
// If this property (i) is an object, then recursively process the object
if (typeof obj[i] == "object") {
if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
}
}
}
With this function we can check what one object content.
Document.Cookie Property Returns an Empty String
- Details
- Category: JavaScript
- Published on Monday, 02 February 2009 14:31
- Hits: 447
This took me some time:
When you use client-side code (the Document.Cookie property) to write cookies, and then use the same method to retrieve the cookies, you may receive an empty string or the following error message:
Increasing day and formating date time
- Details
- Category: JavaScript
- Published on Wednesday, 28 January 2009 13:40
- Hits: 402
First, code for increasig day. If we have date in string, then code would loo something like this:
strYear = strDate.substring(0,4);
strMonth = strDate.substring(5,7);
strDay = strDate.substring(8,10);
ĂÂ ĂÂ ĂÂ
d = new Date(strYear, strMonth - 1, strDay);
d.setDate(d.getDate() + 1);
Then, to format date time, to something like yyyy-mm-dd, I was using this code:
ĂÂ ĂÂ ĂÂ strYear = d.getFullYear();
ĂÂ ĂÂ ĂÂ if (d.getMonth() < 10)
ĂÂ ĂÂ ĂÂ ĂÂ {
ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ intMonth = d.getMonth() + 1;
ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ strMonth = '0' + intMonth;
ĂÂ ĂÂ ĂÂ ĂÂ }
ĂÂ ĂÂ ĂÂ ĂÂ else
ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ {
ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ strMonth = d.getMonth() + 1;
ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ }
ĂÂ
ĂÂ ĂÂ ĂÂ if (d.getDate() < 10)
ĂÂ ĂÂ ĂÂ {
ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ strDay = '0' + d.getDate();
ĂÂ ĂÂ ĂÂ }
ĂÂ ĂÂ ĂÂ else
ĂÂ ĂÂ ĂÂ {
ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ strDay = d.getDate();ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ ĂÂ
ĂÂ ĂÂ ĂÂ }
Finnaly, date would be created something like:
strDate =ĂÂ strYear + '-' + strMonth + '-' + strDay;
getMonth - with this function we are geting number of a month, but from 0, 0 - this is January?
getDate - with this function we are geting number of a day in a month.

