Results 1 to 9 of 9

Thread: setTimeout parameters lost on 3rd call

  1. #1
    Join Date
    Apr 2010

    setTimeout parameters lost on 3rd call

    Hello all,

    I am in the process of creating an ajax like upload control (like the one described here: http://geekswithblogs.net/rashid/arc...le-Upload.aspx ).

    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:

    function beginUploadProgress(Cell) {
        _divUploadProgress.style.display = '';
        _uploadProgressTimer = setTimeout(function() { updateUploadProgress(Cell) }, PROGRESS_INTERVAL);
    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):

    function updateUploadProgress(Cell) {
        _loopCounter += 1;
        if (_loopCounter <= _maxLoop) {
            document.getElementById(Cell + '_tdProgress' + _loopCounter).style.backgroundColor = PROGRESS_COLOUR;
        else {
        if (_uploadProgressTimer) {
        //_uploadProgressTimer = setTimeout(function() { updateUploadProgress(Cell) }, PROGRESS_INTERVAL);
    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?

    Many thanks for your valuable time.


  2. #2
    Join Date
    Dec 2003
    Bucharest, ROMANIA
    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 )

    can't you post a link to test page, instead?

  3. #3
    Join Date
    Apr 2010
    Apologies.. let me give some more info:

    I have an aspx page which is loaded in an iframe. onload of the iframe I call a function called initFileUpload:

    var PROGRESS_INTERVAL = 500;
    var PROGRESS_COLOUR = 'blue';
    var _maxLoop = 10;
    function initFileUpload(Cell) {
        _divFrame = document.getElementById(Cell + '_divFrame');
        _divUploadMessage = document.getElementById(Cell + '_divUploadMessage');
        _divUploadProgress = document.getElementById(Cell + '_divUploadProgress');
        _ifrFile = document.getElementById(Cell + '_ifrFile');
        var btnUpload = _ifrFile.contentWindow.document.getElementById('UploadButton');
        btnUpload.onclick = function(event) {
            var filFile = _ifrFile.contentWindow.document.getElementById('FileToUpload');
            //Baisic validation for Photo
            _divUploadMessage.style.display = 'none';
            if (filFile.value.length == 0) {
                _divUploadMessage.innerHTML = '<span style=\"color:#ff0000\">Please specify the file.</span>';
                _divUploadMessage.style.display = '';
            _divFrame.style.display = 'none';
    Cell is a variable (containing a string) which refers to which area of my application where my upload control resides... there can be multiples.

    I've also included my constants.

  4. #4
    Join Date
    Dec 2003
    Bucharest, ROMANIA
    Quote Originally Posted by HairyMike View Post
    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...

  5. #5
    Join Date
    Apr 2010
    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).

        Public Shared Function GetUploadControl(ByVal Cell As String, ByVal PathID As Integer) As String
            Dim s As New IO.StringWriter
            s.WriteLine("<div id=""{0}_divFrame"">", Cell)
            s.WriteLine("<iframe id=""{0}_ifrFile"" onload=""initFileUpload('{0}')"" scrolling=""no"" frameborder=""0"" " & _
                        "hidefocus=""true"" style=""text-align:center;vertical-align:middle;border-style:none;" & _
                        "margin:0px;width:100%;hieght:55px"" src=""../system/upload.aspx{1}""></iframe>", Cell, "?path=" & PathID & "&cell=" & Cell)
            s.WriteLine("<div id=""{0}_divUploadMessage"" style=""padding-top:4px;display:none""></div>", Cell)
            s.WriteLine("<div id=""{0}_divUploadProgress"" style=""padding-top:4px;display:none;"">", Cell)
            s.WriteLine("<span style=""font-size:smaller"">Uploading file...</span>")
            s.WriteLine("<table border=""0"" cellpadding=""0"" cellspacing=""2"" style=""width:100%"">")
            s.WriteLine("<td id=""{0}_tdProgress1"">&nbsp; &nbsp;</td>", Cell)
            s.WriteLine("<td id=""{0}_tdProgress2"">&nbsp; &nbsp;</td>", Cell)
            s.WriteLine("<td id=""{0}_tdProgress3"">&nbsp; &nbsp;</td>", Cell)
            s.WriteLine("<td id=""{0}_tdProgress4"">&nbsp; &nbsp;</td>", Cell)
            s.WriteLine("<td id=""{0}_tdProgress5"">&nbsp; &nbsp;</td>", Cell)
            s.WriteLine("<td id=""{0}_tdProgress6"">&nbsp; &nbsp;</td>", Cell)
            s.WriteLine("<td id=""{0}_tdProgress7"">&nbsp; &nbsp;</td>", Cell)
            s.WriteLine("<td id=""{0}_tdProgress8"">&nbsp; &nbsp;</td>", Cell)
            s.WriteLine("<td id=""{0}_tdProgress9"">&nbsp; &nbsp;</td>", Cell)
            s.WriteLine("<td id=""{0}_tdProgress10"">&nbsp; &nbsp;</td>", Cell)
            Return s.ToString
        End Function
    I assign the cell when I create the control (it is unique). I am doing my debugging with visual studio 2008.

    The only other code that you haven't seen is the part that handles the file upload. That is working as expected.

    Thanks again..

    I've attached some screenshots of the error:

  6. #6
    Join Date
    Dec 2003
    Bucharest, ROMANIA
    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...
    Last edited by Kor; 04-09-2010 at 09:10 AM.

  7. #7
    Join Date
    Apr 2010
    Hi Kor,

    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:

    document.getElementById('TSK_3_0' + '_tdProgress' + _loopCounter)
    and can see that the object definately exists (as you can see in this attached screenshot).

    Thanks for your help.

  8. #8
    Join Date
    Dec 2003
    Bucharest, ROMANIA
    Yes, I saw at a second glance. Do you have another Global variable called Cell somewhere?

  9. #9
    Join Date
    Apr 2010
    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:

    var myUniqueCellGlobal;
    function beginUploadProgress(Cell) {
        _divUploadProgress.style.display = '';
        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.

    Very frustrating...

    But again, thanks for spending the time

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10411 seconds
  • Memory Usage 2,952KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (6)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (9)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates