Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9040717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:03:46+00:00 2026-06-16T10:03:46+00:00

I need to change the image on my website using 2 select for colour

  • 0

I need to change the image on my website using 2 select for colour and size.

e.g. If I choose the option “Red” under the colour select, and then I choose the option “Small” under the size select, the image should be “small_red.png”.
Similarly, if I choose red and large, then the image should be “red_large.png”

Thus far, I only know how to do it for 1 select, but not multiple select.

Here’s my html:

<img id="imageToSwap" src="img/red.png">

<select id="colour" onChange="swapImage()">
<option value="img/red.png">Red</option>
<option value="img/green.png">Green</option>
</select>

Here’s my javascript:

<script type="text/javascript">
function swapImage(){
    var image = document.getElementById("imageToSwap");
    var change = document.getElementById("colour");
    image.src = change.value;   
};
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:03:47+00:00Added an answer on June 16, 2026 at 10:03 am
    var
      img = document.getElementById('imageToSwap'),
      colour = document.getElementById('colour'),
      size = document.getElementById('size'),
      change;
    
    change = function (evt) {
      img.src = ['img/', size.value, '_', colour.value, '.png'].join('');
    };
    
    colour.addEventListener('change', change, false);
    size.addEventListener('change', change, false);
    

    with:

    <img id="imageToSwap">
    
    <select id="colour">
      <option value="red">Red</option>
      <option value="green">Green</option>
    </select>
    
    <select id="size">
      <option value="small">Small</option>
      <option value="big">Big</option>
    </select>
    

    demo: http://jsbin.com/iwezad/2/


    though, using jQuery this could be shortend a lot, and you’d get rid of some browser quirks regarding addEventListener.


    jQuery version:

    $('#colour, #size').on('change', function() {
      $('#imageToSwap').prop('src', 
        ['img/', $('#size').val(), '_', $('#colour').val(), '.jpg'].join('')    
      );
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to change the color of an image on a website. The image
I need to loop through my website using jquery and change the class selector
I need change first image in Galleria fullscreen theme ( link ) after Galleria.run().
I need to change my mouse cursor to a custom image. If possible I
Possible Duplicate: Android Button: set onClick background image change with XML? I need that
I need to make javascript code to swap images with option change. Here is
I am doing a website using php , i need create a pdf doc
Im using the Wookmark jQuery grid layout for my website. https://github.com/GBKS/Wookmark-jQuery I need the
I have an image displaying on my website homepage, and I need to place
I have some images that need to change, based not only on hover, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.