🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.javascript
Article #52018

Co tu jest źle?

#52018
From: Michal M. Lechanski
Date: Thu, 01 Aug 2019 20:22
62 lines
3082 bytes
Mam taki script w <body> (do head nie mam dostępu), który wyświetlał
losowo jeden z obrazków. Ostatnio dodawałem kolejny obrazek i coś
zepsułem - obrazki się nie wyświetlają. Poza tym wszystko inne działa.

Console z Developer Tools w Firefoksie pokazuje:

TypeError: document.getElementById(...) is null
    loadHomeImage http://lechanski.net/:155
    <anonymous> http://lechanski.net/:158

Podpowiedzcie proszę co zrobiłem źle i jak to naprawić.
Z góry bardzo dziękuję.


Kod:

<script type="text/javascript">
 function loadHomeImage(){
 console.log('loadHomeImage();');
 var imagenumber = 11 ;
 var randomnumber = Math.random() ;
 var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;
 images = new Array;
	
// LIST OF IMAGES
images[0] ='<img src="http://images.fluidfolio.com/x/y/zzz1.jpg">';
images[1] ='<img src="http://images.fluidfolio.com/x/y/zzz2.jpg">'
images[2] ='<img src="http://images.fluidfolio.com/x/y/zzz3.jpg">';
images[3] ='<img src="http://images.fluidfolio.com/x/y/zzz4.jpg">';
images[4] ='<img src="http://images.fluidfolio.com/x/y/zzz5.jpg">';
images[5] ='<img src="http://images.fluidfolio.com/x/y/zzz6.jpg">';
images[6] ='<img src="http://images.fluidfolio.com/x/y/zzz7.jpg">';
images[7] ='<img src="http://images.fluidfolio.com/x/y/zzz8.jpg">';
images[8] ='<img src="http://images.fluidfolio.com/x/y/zzz9.jpg">';
images[9] ='<img src="http://images.fluidfolio.com/x/y/zzz10.jpg">';
images[10] ='<img src="https://images.fluidfolio.com/x/y/zzz11.jpg">';
var image = images[rand1];
captions = new Array;

// LIST OF CAPTİONS
captions[0] = "Pictures: 01";
captions[1] = "Pictures: 02";
captions[2] = "Pictures: 03";
captions[3] = "Pictures: 04";
captions[4] = "Pictures: 05";
captions[5] = "Pictures: 06";
captions[6] = "Pictures: 07";
captions[7] = "Pictures: 08";
captions[8] = "Pictures: 09";
captions[9] = "Pictures: 10";
captions[10] = "Pictures: 11";
var caption = captions[rand1];
document.getElementById('homepage-image').innerHTML = '<img src="' +
image + '" width="auto" height="400px">' + caption;    //linia 155
   };

loadHomeImage();           //linia 158
</script>


-- 
Michał
Technical Details
Message-ID: <qhvhle$14p$1$michal@news.chmurka.net>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.chmurka.net!.POSTED.alhuston.plus.com!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.chmurka.net!.POSTED.alhuston.plus.com!not-for-mail
From: "Michal M. Lechanski" <michal@doriath.eu>
Newsgroups: pl.comp.lang.javascript
Subject: Co tu jest źle?
Date: Thu, 1 Aug 2019 21:22:08 +0100
Organization: news.chmurka.net
Message-ID: <qhvhle$14p$1$michal@news.chmurka.net>
NNTP-Posting-Host: alhuston.plus.com
Mime-Version: 1.0
Injection-Date: Thu, 1 Aug 2019 20:22:07 +0000 (UTC)
Injection-Info: news.chmurka.net; posting-account="michal"; posting-host="alhuston.plus.com:81.174.137.13"; logging-data="1177"; mail-complaints-to="abuse-news.(at).chmurka.net"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Thunderbird/60.8.0
X-Mozilla-News-Host: news://news.chmurka.net:119
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit