#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    60
    Rep Power
    3

    Can anyone tell what's the difference between these code, please?


    I got these two code that were supposed to be identical to each other.

    But one works fine but the other one doesn't and I don't know why..

    I used "http://www.diffnow.com/" for comparison.
    And it tells me number of differences are 0 between them.
    Also, the looks identical to each other( I even looked through them for a couple of times).

    However, I'm not actually confident that these two are exactly the same as each other since only one works fine while the other one doesn't as I said. I might have used the site in a wrong way and misunderstood what it said as a result.


    Anyways, codes are these two.

    First one (one that works fine):


    Code:
    <!DOCTYPE html>
    <html>
    <body>
    
    <script>
    function showCertainCategory(selection)
    {
          var ulTag = document.getElementsByTagName('ul');
    
          for(var i=0; i<ulTag.length; i++)
      {
        ulTag[i].style.display = "none";
        if(ulTag[i].className == selection)
       {
         ulTag[i].style.display = "block";
       }
        else
       {
         ulTag[i].style.display = "none";
       }
      }
    }
    
    </script>
    <form>
    <select id="category" onChange="showCertainCategory(this.value)">
    <option value="handle">handle</option>
    <option value="wheel">wheel</option>
    </select>
    </form>
    
    <ul class='handle'>
    <li>Handle product A</li>
    <li>handle</li>
    </ul>
    <ul class='wheel'>
    <li>Wheel product B</li>
    <li>wheel</li>
    </ul>
    <ul class='handle'>
    <li>Handle product A2</li>
    <li>handle</li>
    </ul>
    <ul class='wheel'>
    <li>Wheel product B2</li>
    <li>wheel</li>
    </ul> 
    
    
    
    
    </body>
    </html>

    ================================================


    Second one(One that doesn't work)

    Code:
    <!DOCTYPE html>
    <html>
    <body>
    
    
    
    <script>
    function showCertainCategory(selection)
    { 
      var ulTag = document.getElementsByTagName('ul');
                  
      for(var i=0; i<ulTag.length; i++)
    	{
    	  ulTag[i].style.display = "none";
    	  if(ulTag[i].className == selection)
    	  {
    	    ulTag[i].style.display = "block";
    	  }
    	   else
    	  {
    	    ulTag[i].style.display = "none";
    	  }
    	}
    }
    	
    </script>
    <form>
    	<select id="category" onChange="showCertainCategory(this.value)">
    		<option value="handle">handle</option>
    		<option value="wheel">wheel</option>
    	</select>
    </form>
    
    <ul class='handle'>
    	<li>Handle product A</li>
    	<li>handle</li>
    </ul>
    <ul class='wheel'>
    	<li>Wheel product B</li>
    	<li>wheel</li>
    </ul>
    <ul class='handle'>
    	<li>Handle product A2</li>
    	<li>handle</li>
    </ul>
    <ul class='wheel'>
    	<li>Wheel product B2</li>
    	<li>wheel</li>
    </ul>
    
    
    
    
    </body>
    
    </html>
  2. #2
  3. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    There are some unusual characters after the "var ulTag" line. Check the attachment.

    Simply delete the line.
    Attached Images
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    60
    Rep Power
    3
    Thank you very much.

    But how did you tell it?

    and is having extra spaces between the lines so bad and why??



    Originally Posted by requinix
    There are some unusual characters after the "var ulTag" line. Check the attachment.

    Simply delete the line.
  6. #4
  7. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,303
    Rep Power
    9400
    I copy/pasted your code into Notepad so I could compare the two more easily. Notepad tends to show those squares for unusual/non-printable characters so they were hard to miss. So it was lucky, really.

    It's not that the extra space is bad, it's what's present on that line. Deleting it makes the problematic characters go away; if you want the blank line then go ahead and add another one in.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    60
    Rep Power
    3
    Well I used Notepad that comes with Windows and I couldn't see any of those problematic characters..

    Did you set it to certain mode or something??



    Originally Posted by requinix
    I copy/pasted your code into Notepad so I could compare the two more easily. Notepad tends to show those squares for unusual/non-printable characters so they were hard to miss. So it was lucky, really.

    It's not that the extra space is bad, it's what's present on that line. Deleting it makes the problematic characters go away; if you want the blank line then go ahead and add another one in.
  10. #6
  11. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,188
    Rep Power
    184
    The unusual characters requinix is referring to; and I am not sure how your missing it is:

    In NotePad

    Code:
                  
    They are right below the "ulTag" variable declaration. On this forum; they are represented as Ruby characters, but if you paste them into Notepad... they will look like small hollow squares. Delete these characters and the code will work fine. You can still keep the carriage return (to create a carriage return; all you have to do is press the "Enter" key, on your keyboard); just remove the characters.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    56
    Rep Power
    28
    Some fonts will display nothing even in notepad for certain characters. Terminal is one of them. If you switch your font to Terminal in notepad you will quickly see how they could not see them.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    60
    Rep Power
    3
    well, I tried that font and other fonts too but it didn't work out that way.

    I will just highlight everything so that I will find highlighted part that doesn't have any characters where it should be unusual characters.

IMN logo majestic logo threadwatch logo seochat tools logo