web-eagle
04-23-2003, 09:45 PM
I’m not getting it. (duh)
I want to have a group of images with links, which are displayed “shuffled” each time the page loads. That is I want the whole group displayed, but always in a different, random order.
I’ve tried populating a two-dimensional array in various ways, but so far haven’t gotten it to work. For now I’ve just resorted to three separate arrays.
The first (pos) array will contain a random number (0-1), which will be the sort key for all arrays. But I don’t know how (or if it’s possible) to cause the img and lnk arrays to follow the pos array. (One language I’ve used had a TagArray option. Does anything like that exist in JS?) Do I just need to give up and code a bubble sort and manually follow the other two arrays?
pos = new Array(5)
img = new Array(5)
lnk = new Array(5)
pos[0] = Math.random()
pos[1] = Math.random()
pos[2] = Math.random()
pos[3] = Math.random()
pos[4] = Math.random()
img[0] = "img1.gif"
img[1] = "img2.gif"
img[2] = "img3.gif"
img[3] = "img4.gif"
img[4] = "img5.gif"
lnk[0] = "link1.htm"
lnk[1] = "link2.htm"
lnk[2] = "link3.htm"
lnk[3] = "link4.htm"
lnk[4] = "link5.htm"
I did try concatenating the arrays, giving me something like "0.4363734 img1.gif link1.htm", which is sortable, but I'm not sure how to parse that.
Can anybody give me some ideas? I did a forum search, and a couple of similar questions came up in March, but they don’t seem to apply here.
Thanks for any and all help.
I want to have a group of images with links, which are displayed “shuffled” each time the page loads. That is I want the whole group displayed, but always in a different, random order.
I’ve tried populating a two-dimensional array in various ways, but so far haven’t gotten it to work. For now I’ve just resorted to three separate arrays.
The first (pos) array will contain a random number (0-1), which will be the sort key for all arrays. But I don’t know how (or if it’s possible) to cause the img and lnk arrays to follow the pos array. (One language I’ve used had a TagArray option. Does anything like that exist in JS?) Do I just need to give up and code a bubble sort and manually follow the other two arrays?
pos = new Array(5)
img = new Array(5)
lnk = new Array(5)
pos[0] = Math.random()
pos[1] = Math.random()
pos[2] = Math.random()
pos[3] = Math.random()
pos[4] = Math.random()
img[0] = "img1.gif"
img[1] = "img2.gif"
img[2] = "img3.gif"
img[3] = "img4.gif"
img[4] = "img5.gif"
lnk[0] = "link1.htm"
lnk[1] = "link2.htm"
lnk[2] = "link3.htm"
lnk[3] = "link4.htm"
lnk[4] = "link5.htm"
I did try concatenating the arrays, giving me something like "0.4363734 img1.gif link1.htm", which is sortable, but I'm not sure how to parse that.
Can anybody give me some ideas? I did a forum search, and a couple of similar questions came up in March, but they don’t seem to apply here.
Thanks for any and all help.