Annoying problem

Discussion in 'HTML & Website Design' started by Solong, Jul 5, 2013.

  1. #1
    I have gotten some valuable help from digital point and have almost built my first website. The website is basically a site where you click a button and a random picture will appear.

    Here's the code, don't mind the script and css tags. I just didn't wanna paste all the code:

    CSS
      #container #rating-container{
              position:absolute;
              left:600px;
              top:400px;
             
             
              }
    SCRIPT
      var myImages = new Array();
     
      myImages[0] = "ett.jpg";
      myImages[1] = "tva.jpg";
      myImages[2] = "tre.jpg";
      myImages[3] = "fyra.jpg";
     
      var myDouble = new Array();
     
      myDouble[0] = "soso1.png";
      myDouble[1] = "soso2.png";
      myDouble[2] = "soso3.png";
      myDouble[3] = "soso4.png";
     
      var myLinks = new Array();
     
      myLinks[0] = "http://dt.se";
      myLinks[1] = "http://gamereactor.se";
      myLinks[2] = "http://aftonbladet.se";
      myLinks[3] = "http://existenz.se";
     
      var myTexts = new Array();
     
      myTexts[0] = "Hello this is cool osv nu ska jag<br /> skriva en massa for att fa en storre text";
      myTexts[1] = "Mej kan du inte hemma och typ sant om kan hu bli vad det nu ar tinkle belly boo boo skittlefest med torra banor och jiggly kalas dy vet val att man inte far go sa";
      myTexts[2] = "Har du kalas";
      myTexts[3] = "Skola en bootlegger";
     
      var rnd = Math.floor(Math.random() * myImages.length);
      if (rnd == 0){
          rnd = 1;
      }
      // set image
      document.getElementById('image-container').innerHTML = '<a href="'+myLinks[rnd]+'"><img src="'+myImages[rnd]+'" /></a>';
      // set caption
      document.getElementById('caption-container').innerHTML = '<p>'+myTexts[rnd]+'</p>';
      // set rating
      document.getElementById('double-container').innerHTML = '<img src="'+myDouble[rnd]+'" />';
      
    Code (markup):
    What I wanna do now is to add another picture into the array that is shown under the first one. What to do?
     
    Solong, Jul 5, 2013 IP
  2. themes4all

    themes4all Well-Known Member

    Messages:
    662
    Likes Received:
    47
    Best Answers:
    6
    Trophy Points:
    100
    #2
    Basicly you will have to make some changes on the code, if i understand you need to add an image just under the myImages[0] = "ett.jpg"; so your code must be :

    
      myImages[0] = "ett.jpg";
      myImages[1] = "The-NEW-IMAGE.jpg";
      myImages[2] = "tva.jpg";
      myImages[3] = "tre.jpg";
      myImages[4] = "fyra.jpg";
     
      var myDouble = new Array();
     
      myDouble[0] = "soso1.png";
      myDouble[1] = "The-NEWS-IMAGE-soso1.png";
      myDouble[2] = "soso2.png";
      myDouble[3] = "soso3.png";
      myDouble[4] = "soso4.png";
     
      var myLinks = new Array();
     
      myLinks[0] = "http://dt.se";
      myLinks[1] = "http://THE-NEW-IMAGE-URL";
      myLinks[2] = "http://gamereactor.se";
      myLinks[3] = "http://aftonbladet.se";
      myLinks[4] = "http://existenz.se";
     
      var myTexts = new Array();
     
      myTexts[0] = "Hello this is cool osv nu ska jag<br /> skriva en massa for att fa en storre text";
      myTexts[1] = "THE NEW IMAGE TEXT";
      myTexts[2] = "Mej kan du inte hemma och typ sant om kan hu bli vad det nu ar tinkle belly boo boo skittlefest med torra banor och jiggly kalas dy vet val att man inte far go sa";
      myTexts[3] = "Har du kalas";
      myTexts[4] = "Skola en bootlegger";
    
    Code (markup):
    Goodluck
     
    themes4all, Jul 5, 2013 IP
  3. Solong

    Solong Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3

    Maybe I didn't explain too good.

    I have one picture that when I click a button turns into another random picture. All of the arrays are in one function, the randomImg() function. So only one picture shows at a time and now I wanna add a picture that is associated with the random picture.

    In my code, the myDouble variable is supposed to be the associated picture. So myDouble[0] = "soso1.png"; should be associated with myImages[0] = "ett.jpg";. But now the code doesn't work and the myDouble picture doesn't show...
     
    Solong, Jul 5, 2013 IP