Question

I cannot seem to access the context object using a loop context is set: var context = [id1, id2, id3];

This callback function works:

function OnChangeSucceeded(result, context, methodName) {
    document.getElementById(context[0]).disabled = result;
    document.getElementById(context[1]).disabled = result;
    document.getElementById(context[2]).disabled = result;
}

This callback function fails:

function OnChangeSucceeded(result, context, methodName) {
        for(var indx = 0; indx < context.length; indx++) {
           document.getElementById(context[indx]).disabled = result;
        }

    }
Was it helpful?

Solution 3

Thats for the pointer to firebug tvanfosson.

I have redone the function and it now works as:

function OnChangeSucceeded(result, context, methodName) {
    for (controlId in context) {
        document.getElementById(context[controlId]).disabled = result;
    }
}

I am not sure if it was because the context was original created as:

context = [id1, id2, id3];

which I have now replaced with:

context = new Array(id1, id2, id3);

OTHER TIPS

It would be handy to see the calling code so that we could see how your context is established. I'm going to guess that you've set it up as an association and not an array so that when you go to use it in the callback, there is no length property (or it's 0).

When you set it up it should look like:

var context = new Array();
context[0] = 'elem0';
context[1] = 'elem1';
context[2] = 'elem2';

not

var context = { 0: 'elem0', 1: 'elem1', 2: 'elem2' };

If that isn't the problem, then try checking it out in FireFox/FireBug by setting a breakpoint in the onChangeSucceeded function and examining the actual context object to see what properties it has.

Is it because of your typo?

for(var index = 0; indx < context.length; indx++) {

should be

for(var indx = 0; indx < context.length; indx++) {
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top