SitePoint Sponsor

User Tag List

Page 3 of 3 FirstFirst 123
Results 51 to 52 of 52
  1. #51
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    520
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.

    You mentioned earlier that the 'i' was undeclared too. Should I also get rid of it or declare it in this:

    Code:
    function CollapseAll() {
    for (i=0; i<=Menu.length-1; i++) {
    		document.getElementById('Menu'+Menu[i]).style.display = 'none';
    }
    }
    And if I should declare it, do I just add a line like this:

    Code:
    var i='0';

  2. #52
    SitePoint Guru
    Join Date
    Feb 2005
    Posts
    602
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can declare the var within the for statement:

    Code:
    for (var i = 0; i < Menu.length; i++) {
    	document.getElementById('Menu'+Menu[i]).style.display = 'none';
    }
    Also, 0 and '0' are very different. 0 is the number 0, while '0' is the string of 0. Adding numbers or strings to the string appends them to it (concatenation) (e.g. '0' + '1' => '01', '0' + 1 => '01', 0 + '1' => '01'). Numbers are simply added (e.g. 0 + 1 => 1). To get from string to number, you have to use parseInt(str, radix) or parseFloat(str, radix), where parseInt converts to integer and parseFloat converts to floating point numbers.


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
  •