SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calling a function from a function (non-recursive functions)

    Hello,

    It is a very silly thing going on here.

    I am calling a function from a function and it doesn't work. Unfortunately for reason my firefox is not working on my computer, otherwise using firebug, I would have debugged. can someone take a look at this issue please?


    Code:
    <script type="text/javascript">
                
                function ClearLabelControls()
               {
                     var allLabels = document.getElementById("LabelPortfolioCounts").getElementsByTagName("span");
    
                    var i = 0;
                    var len = allLabels.length;
    
                    for (i; i < len; i++) {
    
                        allLabels[i].innerHTML = "";
    
                    }                
    
    
               }
                function PerformChecks() {
    
                    //first clear all controls
                    
                    ClearLabelControls();
                   
                    var vartextboxEOM = document.getElementById('<%= TextBoxPeriod.ClientID%>').value;
    
                    var vardropdownEOM = document.getElementById('<%= DropDownListEOMDates.ClientID %>');

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,095
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    The i looks very lonely as the initialisation of for (i; i < len; i++). Maybe it works but I've never seen it (and I'm pretty sure it won't work but without wanting to look at the official spec I can't be 100% sure).

    Instead it should be for (i=0; i < len; i++)

    Then you can also rewrite

    Code:
    var i = 0;
    var len = allLabels.length;
    to

    Code:
    var i, len = allLabels.length;
    because you don't need to initialise i outside the loop, just declaring it is enough.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    There doesn't seem to be anything wrong with the code from what we've seen of it yet.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Making for (i=0; i < len; i++) does the trick.

    thanks folks


Bookmarks

Posting Permissions

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