son Posted September 15, 2011 Share Posted September 15, 2011 I am working on this script in other post which is not resolved yet, but have a general Javascript question relating to this. When I try to use:function loadThumbs(){ for(var i=0; i < imageArray.length; i++) { thumbPath = '<a id="' + i + '" href="#" onclick="thumbClick(this.id);return false;"><img src="' + imageDir + '/thumb/' + imageArray + '" alt="Photography" /></a>'; $('#thumbnails').append(thumbPath); }}nothing is being appended to the div called 'thumbnails'. When I directly place:<div id="thumbnails"><script type="text/javascript"> for(var i=0; i < imageArray.length; i++) { thumbPath = '<a id="' + i + '" href="#" onclick="thumbClick(this.id);return false;"><img src="' + imageDir + '/thumb/' + imageArray + '" alt="desc" /></a>'; } </script></div>the thumbs are displayed. I do not get it. What is the difference? I call the loadThumbs function higher on as$(document).ready(function() { getTotal();});function getTotal(){ $.get(imageDir + "/thumb/files.php", function(data){ imageArray = data.split("|"); imageArray.pop(); imageTotal = imageArray.length; imageNo = 1; loadNavi(); // load thumbnails loadThumbs(); });} Where am I going wrong with this? Son Link to comment Share on other sites More sharing options...
justsomeguy Posted September 15, 2011 Share Posted September 15, 2011 Are you checking for errors? Are you sure that function is being called? Link to comment Share on other sites More sharing options...
son Posted September 16, 2011 Author Share Posted September 16, 2011 How would I check for errors? The page does not show any issues as such... Son Link to comment Share on other sites More sharing options...
justsomeguy Posted September 16, 2011 Share Posted September 16, 2011 Check in the browser's error console. Link to comment Share on other sites More sharing options...
son Posted September 16, 2011 Author Share Posted September 16, 2011 I did this before, but there are no errors whatsoever. However, I tried nowdocument.write(imageArray.length); which shows 0anddocument.write(imageTotal); which brings up 'undefined'but I am not getting why the function would not be called. I have at top$(document).ready(function() { getTotal();});// FUNCTIONS BELOW// get image totalfunction getTotal(){ $.get(imageDir + "/thumb/files.php", function(data){ imageArray = data.split("|"); imageArray.pop(); imageTotal = imageArray.length; imageNo = 1; loadNavi(); // load thumbnails loadThumbs(); });}and thought $(document).ready(function() calls the function?Am I wrong with this assumption? Son Link to comment Share on other sites More sharing options...
thescientist Posted September 16, 2011 Share Posted September 16, 2011 as said, check the error console. Just google it for your browser if you don't know how to get to it. using document.write is an extremely bad practice. it will reload the page if you call it after the page has already loaded. Also, please use code tags when posting, if you have any formatting, it will be preserved and will make sight reading your code easier for everyone. in jquery, ready is a method that will be executed once the DOM has loaded. It is common practice to put any code inside so element references will be valid.http://api.jquery.com/ready/ once you have found your console, I would do heavy logging using console.log. log when a function gets called, what the data is, everything you can to help trace the execution of your script. Link to comment Share on other sites More sharing options...
son Posted September 19, 2011 Author Share Posted September 19, 2011 When I said 'I did this before, but there are no errors whatsoever.' that was meant to say that I checked the errro console, but there are no errors, warning, messages whatsoever... I only used document.write to see what the values are, this should have not been in the 'real' life script, but I am open to suggestions how to be check what values are when I am debugging. What would you normally use? Also, what do you mean by logging everything? The error console does this automatically, doesn't it? Son Link to comment Share on other sites More sharing options...
thescientist Posted September 19, 2011 Share Posted September 19, 2011 console.log('ENTER function xyz');console.log('the value of x is => ' + x);console.log('the value of y is => ' + y); It's up to you to figure out what is going on at all times over the course of your script. The console is just where errors and logging shows up. The logging is not automatic. edit: the old way is to use alert, but that's such a PITA... Link to comment Share on other sites More sharing options...
son Posted September 19, 2011 Author Share Posted September 19, 2011 Thanks. Will try this... Son Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.