I have ran into an unexpected problem that I can't seem to find a solution to. Javascript is not my favoured tech, and maybe there is something fundamental about this that I don't understand. I would really appreciate if someone could point out what I'm doing wrong:
I am using setTimeout to basically show a dummy progress bar (by manipulating backcolour of td elements). I start the process like this:
This initiates properly, and I can see the first 2 td elements being coloured, then I get an error in my updateUploadProgress routine (Cell is undefined):
I'm sure there is nothing happening to the Cell variable, but I have a feeling there is something about the scope of the Cell variable that I don't understand. Anyone have any idea why it might be coming up as 'undefined' for the 3rd call of updateUploadProgress?
Insufficient data. We see too many variables defined elsewhere to be able to understand where the error. No, there is nothing with the scope of the Cell variable. (except maybe we don't know what kind of variable is and where was it defined )
Anyone have any idea why it might be coming up as 'undefined'
What becomes "undefined"? Are you talking about the variable Cell? Cell is a primitive (if it was defined as a simple string), thus it can not become undefined.
Who said "undefined"? The browser's error console? Which is the error message? maybe something else is undefined, maybe your 3rd element with that id is undefined, but not the string variable.
Things remains a little bit unclear for me, i confess...
Yes, it has me stumped as well. I am working on a single page ajax app. My code is brought from the server through webservice calls in ASP.NET, like this (not pretty).
aha... "Object required" means, probably, that element (probably a td element) with that certain id does not exist. Can you test the document in FireFox with the Firebug extension?
I don't know much about Visual Studio and ASP.NET - only my colleagues work with, as I cover the php/mySQL area... I don't know what to say...
If you look at the screenshot titled 'debug1.jpg' in my previous post, you should be able to see 'undefined' beside the Cell variable. When I break execution of my javascript, visual studio can show me the value of variables that are currently in scope (It is slightly faded in the screenshot, but still visible)..
I am positive that the element exists. I can put a watch on this:
That is what I had initially thought.. but after extensive checking, I can be sure that no other global variables are called 'Cell' (the only globals I've created are the constants for this control).
I thought maybe Cell might be a system variable, so I tried this:
Code:
var myUniqueCellGlobal;
function beginUploadProgress(Cell) {
_divUploadProgress.style.display = '';
clearUploadProgress(Cell);
myUniqueCellGlobal = Cell;
_uploadProgressTimer = setTimeout(function() { updateUploadProgress(myUniqueCellGlobal) }, PROGRESS_INTERVAL);
}
I also changed the name of the params in updateUploadProgress to myCell.
I've been able to step through this and see that the right value is going into the _uploadProgressTimer's parameter (same as it does when using 'Cell').
So what is happening is that the function succeeds twice before the variable becomes undefined.. It doesn't seem to matter what I call the variables, the result is always the same.
Bookmarks