Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay 3 random images in Javascript from an javascript array of image links that have come from a database
    primarykey
    data
    text
    <p>I am struggling to take 3 random images (No repeat) out of my Javascript array and print them on screen within separate Divs.</p> <p>My Javascript array is being populated by a database which contains the links/location of the images on the server. </p> <p>Currently my page looks like this:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt;&lt;/div&gt; &lt;script&gt; var items = [ {name:'Coch',image:'upload/coch.png'},{name:'Glas',image:'upload/glas.png'}, {name:'Melyn',image:'upload/melyn.png'},{name:'Ci',image:'upload/dog.jpg'}, {name:'Cath',image:'upload/cath.jpg'},{name:'Gwyrdd',image:'upload/gwyrdd.png'},{name:'Un',image:'upload/un.jpg'},{name:'Dau',image:'upload/dau.jpg'},{name:'Tri',image:'upload/tri.jpg'},{name:'Bochdew',image:'upload/bochdew.jpg'},{name:'Piws',image:'upload/piws.png'} ]; for (var i = 0; i &lt; items.length; i += 1) { document.getElementsByTagName('div')[0].innerHTML += items[i].name + " / " + items[i].image + "&lt;br /&gt;\n"; } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>This code simply takes the image links from the database and inserts them into a javascipt array. (And prints the links on screen at the moment)</p> <p>Can anyone give me any help on how to get this to work? Take 3 random images links from that array (No duplication's), and display the 3 images on screen in 3 different divs.</p> <p>I am not good with javascipt at all and any code examples would be great.</p> <p>Thank You in advance for any replies.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload