Enumerating JavaScript Object Properties

I am building a few controls that use client-side script for reuse in the one web app I'm working on. I needed a way to enumerate the property names and values of an object in JavaScript so I knew which properties I had access to. Here's a JavaScript method I put together to enumerate the properties of a CustomValidator object. I have the function name as the value of the ClientValidationFunction:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function myValidator(source, args) 
{
    var property, propCollection = "";

    for(property in source.parentElement)
    {
        propCollection += (property + ": " + source[property] + "\n");
    }
    
    alert(propCollection);

    // For now, show the entry as invalid
    args.IsValid = false;
}

1 Comment

Comments have been disabled for this content.