Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    43
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Validation woes...

    I've got 9 errors when I try to validate the data and can't figure out what's wrong with them...I've tried a number of doctypes and they all have the same errors.


    This is the constructor: The first error is in the first for loop it doesn't like the < sign when comparing i < num.

    Then it doesn't like the ' in the innerHTML part where '<div id="pfs'+i+'">

    Code:
    function MakeGallery(obj){
    		var Gallery = {
    			name:obj.name,
    			images:obj.imgs,
    			heading:obj.heading,
    			populate: function(){
    				var elemID = document.getElementById(Gallery.name);
    				for(var i = 0, num=Gallery.images.length; i < num; i++){			
    					elemID.innerHTML +='<div id="pfs'+i+'"><pre>'+Gallery.heading+'</pre><a href="/images/'+Gallery.images[i]+'"></a><img src="images/'+Gallery.images[i]+'" onclick="toggleShowcase(this.src);" alt="video game gallery images" /></div>';
    				}
    			},
    			depopulate: function(){			
    				for(var i=0, max=Gallery.images.length; i < max; i++){
    					$('#'+'pfs'+i).remove();					
    				}
    			}			
    		}
    		Gallery.populate();
    		return Gallery;	
    	}
    	function RemovePics(wh){			
    				wh.depopulate();
    	}
    	function AddPics(wh){			
    				wh.populate();
    	}

    and the rest of the errors are similar. If you try to validate leefromseattle.com/gallery.html you can see the errors. They're all to do with either > symbols in for loops or ' single quotes used concatenating strings in my innerHTML.

    Any ideas?

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,091
    Thanks
    38
    Thanked 498 Times in 492 Posts
    Gallery is an object, not an array. Gallery.images is another object.

    You cannot access the objects using array syntax. Hence the errors.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Is obj.imgs an array?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    New Coder
    Join Date
    May 2011
    Posts
    43
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv View Post
    Is obj.imgs an array?
    Yes, sorry thought I included that: There's 3 objects like this, each is a "category", as an array of image names strings.
    Code:
    var BlenderImgs = { //Blender Screenshots
    	name:'youngAnimalGame',
    	imgs: ['heightmap_orig.jpg','UOmaporig.jpg','canyon_orig.jpg','racecourse_orig.jpg','rpgLevel_orig.jpg','village_orig.jpg'],
    	heading: ' Blender Modeling'
    }
    It works fine but doesn't validate because of ' when concatenating and > in for loop ...
    Last edited by nuBee; 04-14-2013 at 02:48 AM.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Oh you were trying to do HTML validation through http://validator.w3.org/. I thought there were some js errors and you were trying to fix them.

    Your script inline with the HTML, right? If you put the script in a js file and include it in the HTML, then you wouldn't have any HTML validation error. But if you really want to put it inline, then you need to enclose the script inside <![CDATA[ and ]]>

    Code:
    <script type="text/javascript">
    <![CDATA[
        //you script here
    ]]>
    </script>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • Users who have thanked glenngv for this post:

    nuBee (04-14-2013)

  • #6
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,091
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question What ....

    Quote Originally Posted by glenngv View Post
    Oh you were trying to do HTML validation through http://validator.w3.org/. I thought there were some js errors and you were trying to fix them.

    ...
    @glenngv
    How in the world did you figure that out from the information given ???

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by jmrker View Post
    @glenngv
    How in the world did you figure that out from the information given ???
    By this:
    Quote Originally Posted by nuBee
    It works fine but doesn't validate
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #8
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,091
    Thanks
    38
    Thanked 498 Times in 492 Posts
    Aha, I missed that little line.

  • #9
    New Coder
    Join Date
    May 2011
    Posts
    43
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Sorry I should have been clearer. I'm heavily medicated if that's an excuse.

    Honestly I must never use javascript in-line or maybe I've never cared about validation because I've never seen that CDATA part lol... nowadays I try to validate everything just learn if not to make it run the same cross browser.

    I learned about IE "quirks mode" the hard way after burning a couple hours pulling my hair out...


  •  

    Posting Permissions

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