jdubwelch Posted December 6, 2007 Share Posted December 6, 2007 i have 32 images in a folder. they're named: 0.gif, 1.gif, 2.gif,..., 30.gif, 31.gif I want to preload all those images. Preloader is my function that doesn't work and makes my other function "setWinner" to not work. <script language="JavaScript" type="text/javascript"> <!-- function setWinner(clickedObjId,row) { document.getElementById('row'+row).innerHTML = '<div align="center"><img src="team_logos/' + clickedObjId + '.gif" width="80" height="80" /></div>'; document.getElementById('winner'+row).value = clickedObjId; } function preloader () { imageObj = new Image(); for(var i=0, i<=31; i++) { imageObj.src = 'team_logos/' + i + '.gif'; } } // --> </script> Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 6, 2007 Share Posted December 6, 2007 row is outside the scope of document.getElementById; that's why you first function isn't working. Quote Link to comment Share on other sites More sharing options...
jdubwelch Posted December 6, 2007 Author Share Posted December 6, 2007 What does that mean? How do i fix it? Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 6, 2007 Share Posted December 6, 2007 try this and see if it correct the issue: <script language="JavaScript" type="text/javascript"> <!-- function setWinner(clickedObjId,row) { document.getElementById('row'+row+'').innerHTML = '<div align="center"><img src="team_logos/' + clickedObjId + '.gif" width="80" height="80" /></div>'; document.getElementById('winner'+row+'').value = clickedObjId; } function preloader () { imageObj = new Image(); for(var i=0, i<=31; i++) { imageObj.src = 'team_logos/' + i + '.gif'; } } // --> </script> Quote Link to comment Share on other sites More sharing options...
jdubwelch Posted December 7, 2007 Author Share Posted December 7, 2007 It didn't work. Quote Link to comment Share on other sites More sharing options...
nogray Posted December 7, 2007 Share Posted December 7, 2007 You're using a "," comma in your for statment where is suppose to be a ";" semicolen this for(var i=0, i<=31; i++) should be for(var i=0; i<=31; i++) Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 7, 2007 Share Posted December 7, 2007 auh - I didn't catch that - good eye nogray Quote Link to comment Share on other sites More sharing options...
jdubwelch Posted December 8, 2007 Author Share Posted December 8, 2007 thanks. Is there anything for javascript that will point the errors out like php does? Php tells you which line your error is on and makes it a little easier if you happen to have a ',' instead of a ';' Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 8, 2007 Share Posted December 8, 2007 download FireBug for FireFox - it is a add-on and it will help you find your errors. if I had tested your code in FireBug; I would have caught your error - just a visual over look on my end. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.