change image source base on 2 dropdownlist

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • reyzky
    New Member
    • May 2012
    • 2

    change image source base on 2 dropdownlist

    hi,
    I am looking for a javascript that will change the image display or link base on two dropdown lists. Meaning if i have 4 options on first list and another 4 options on the second list i will have 16 combinations or 16 images. Thank you.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Post your code even if it's HTML only, so that we have a better chance of providing a solution.

    Comment

    • reyzky
      New Member
      • May 2012
      • 2

      #3
      something like this except that i need two dropdownlists.

      Code:
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <style type="text/css">
      img{
      height:200px;
      width:250px;
      display:block;
      margin-top:10px;
      }
      #caption{
      font-family:Verdana,tahoma,arial;
      font-size:10pt;
      text-align:center;
      display:block;
      width:250px;
      }
      </style>
      <script type="text/javascript">
      /************************************************************
      * Script by : Raymond Angana
      * Title: Dropdown Based Picture w/ Captions
      * First seen in AFHB2000.com
      * rangana in AHFB2000.com
      * Created June 5, 2008
      * This notice must stay intact
      /**********************************************************/
      window.onload=function()
      {
      	var caption=['Default Image Caption',
      				'Caption1',
      				'Caption2',
      				'Caption3',
      				'Caption4',
      				'Caption5',
      				'Caption6',
      				'Caption7',
      				'Caption8',
      				'Caption9'], // This will be your images caption
      	bp='http://h1.ripway.com/rangana/images/', //base url of your images
      	imgnum=14, //Number of your images. This should match on your comboboxes options.
      	thumb=document.getElementById('thumb'), //id of your image that will be changing
      	description=document.getElementById('caption'), //id of your caption
      	combobox=document.getElementById('selection'); // id of your combobox.
      	
      	combobox.onchange=function()
      	{
      	thumb.src=bp+'Picture'+this.value+'.jpg';
      	description.innerHTML=caption[this.value];
      	}
      }
      </script>
      </head>
      <body>
      <label>Please Change the default picture: </label>
      <select id="selection">
      <option>Change Picture</option>
      <option value="1">Image 1</option>
      <option value="2">Image 2</option>
      <option value="3">Image 3</option>
      <option value="4">Image 4</option>
      <option value="5">Image 5</option>
      <option value="6">Image 6</option>
      <option value="7">Image 7</option>
      <option value="8">Image 8</option>
      <option value="9">Image 9</option>
      </select>
      <br>
      <img src="http://h1.ripway.com/rangana/images/Picture1.png" alt="mypic" id="thumb">
      <span id="caption">Caption for the default Image</span>
      </body>
      </html>
      Last edited by acoder; May 29 '12, 03:45 PM. Reason: Please use [code] tags when posting code

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        What would the values of the second dropdown be and what would be the name of the image files?

        Line 48 is where the image source is set.

        Comment

        • dailynn
          New Member
          • Aug 2012
          • 3

          #5
          I'm also having a similar problem, if I were to post my two sets of drop down codes would you be able to help me?

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Sure, though if the problem is different, I will split it off into its own thread.

            Comment

            • dailynn
              New Member
              • Aug 2012
              • 3

              #7
              It currently has its own thread here :

              Comment

              Working...