Random Image Button

Hello, I have tirelessly been doing research for the past 4 days with no success.

On my Wix Site, I have a set of 100 images in a folder, as well as in a datasheet (both contain the same images), each one labeled “image1” to “image100”. I am working from a lightbox with a row of 5 images that are hidden below 5 icon buttons. What I am trying to do is have a user click on an icon button that will then have a random picture from my datasheet or uploaded image folder randomly generate in the place of the hidden image (with the same dimensions as the hidden image).

To explain further, I have no experience in coding and such, but am highly driven to solve this problem. I have been creating a D&D style tabletop game and people have been asking me to make things easier, so instead of drawing cards (this is just 1 deck) I am trying to simulate that experience by clicking a button online.

For navigational understanding, The top of the page is set and has Two buttons (Quests, Cards) on it while the remainder of the page is scrollable so people can read campaign dialogue as they go. When clicking on the Cards Button it activates a Lightbox with the different decks of cards to choose from. Each deck activates a different light box with the appropriate amount of cards that would be drawn, and in this case 5 cards.

I have found this Random Image page and attempted to integrate the code to the best of my knowledge but it does not seem to work. I have found other pages with similar information but due to my limited knowledge I am finding my success severely lacking.

Please, any Help I can get would be greatly appreciated!

1 Like

Please post your code.

Thank you for responding! Here is the code I have. When I hover over the red dot it says "Parsing error: ‘import’ and ‘export’ may only appear at the top level.

Yes, when you import API’s you have to do it outside all other brackets. Also, you should only have one onReady function.

Delete everything before import wixWindow including the bracket, make sure to replace the word ‘image’ in ‘items[rnd].image’ with the field key of your database column and try running it again.

Hi Allen, did you get this sorted? If so do you have a link to your WIX website, as I would love to see what you did with the code:)
Many thanks,
David

Has anyone had any success with creating this function?

We have managed to create a random product, but the add to cart is not working correctly. Can anyone tell me what the code is to send the selected random image to cart please?