Jump to content

Append dropdown value to img src


biggieuk

Recommended Posts

Hi,

 

Im having a little problem with my dropdown. It is populated dynamically from images inside a folder.

 

I have a 'preview button' next to the dropdown which i would like (when clicked) to popup a window displaying the image in the dropdown.

 

I tried making the preview button have code along the lines of:

 

<img src="../images/uploaded/+document.getElementById.[imgdropdown].value" />

 

however this didnt work.

 

Thanks for any help with this!

Link to comment
https://forums.phpfreaks.com/topic/136437-append-dropdown-value-to-img-src/
Share on other sites

Here's a very simple example. It requires that you have the images (one.jpg, two.jpg & three.jpg) on the local computer inthe folder "C:\img\". However, the same logic would work for images on a web server.

 

<html>
<head>
<script>

function showImg(selID)
{
    selObj = document.getElementById(selID);
    selValue = selObj[selObj.selectedIndex].value;
    window.open('c:\\img\\' + selValue + '.jpg');
}

</script>
</head>

<body>

<select name="img" id="img">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
</select>
<button onclick="showImg('img');">Show Image</button>

</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.