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
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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.