Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
Display image based on user selection in two-level cascading dropdown javascript

So, I have two cascading dropdowns, both displaying different images based on user selection. But now I need to restrict the number of images in the second dropdown based on the first dropdown value.

This is an example of how I did that with fonts: https://jsfiddle.net/gjq8ov1h/

But now, I want to do this with images, but I don't even know where to begin.

fyi, I have the first set of images in order like pic1.jpg, pic2.jpg, but the second set is numbered based on its dimensions. i can change rename them with num1, num2, etc. if needed.

I used these both functions to get the images:

var imageList = Array();

for (var i = 1; i <= 8; i++) {

imageList[i] = new Image();

imageList[i].src = "Images/image"+i+".jpg";

}

function switchImage() {

var selectedImage = document.myForm.switch.options[document.myForm.switch.selectedIndex].value;

document.myImage.src = imageList[selectedImage].src;

}

And this for the second one:

function swapImage(){

var image = document.getElementById("imageToSwap");

var dropd = document.getElementById("dlist");

image.src = dropd.value;    
}

I really can't seem to figure it out. Would appreciate any help!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!