Announcement

Collapse
No announcement yet.

Need Help with Javascript Image Swap

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Need Help with Javascript Image Swap

    In one of my product pages I am trying to use the code below for an image swap. It does work but I need to add the image path and file extension in for the attribute charge to work correctly and I'm drawing a blank.

    This is the full image name and path:
    ../images/products/MAG_BBM/BBM1001.jpg

    For the life of me I am not having any luck adding the image path and file extension in my script. So I need this "../images/products/MAG_BBM/" added to the front and this ".jpg" added at the end. Any help would be greatly appreciated.



    <script language="javascript">
    <!--

    function showimage()
    {
    if (!document.images)
    return
    document.images.backimage.src=
    document.PRODADD.picture.options[document.PRODADD.picture.selectedIndex].value
    }
    //-->
    </script>




    <select name="Product_Attributes[35]:value" id="picture" onChange="showimage()">
    <option value="stock_back" selected>Stock Back (Free)</option>
    <option value="BBM1001">BBM1001 (+5¢/each)</option>
    <option value="BBM1002">BBM1002 (+5¢/each)</option>
    <option value="BBM1003">BBM1003 (+5¢/each)</option>
    </select>


    Thanks,
    Mike

    #2
    You may have already figured this out, but I think you are looking for something like this:
    Code:
    '../images/products/MAG_BBM/' + document.getElementById('picture').options[document.getElementById('picture').selectedIndex].value + '.jpg';

    Comment

    Working...
    X