biggieuk Posted December 10, 2008 Share Posted December 10, 2008 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 More sharing options...
Psycho Posted December 11, 2008 Share Posted December 11, 2008 And where's your code? Link to comment https://forums.phpfreaks.com/topic/136437-append-dropdown-value-to-img-src/#findComment-712532 Share on other sites More sharing options...
Psycho Posted December 11, 2008 Share Posted December 11, 2008 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 https://forums.phpfreaks.com/topic/136437-append-dropdown-value-to-img-src/#findComment-712541 Share on other sites More sharing options...
biggieuk Posted December 11, 2008 Author Share Posted December 11, 2008 Thanks mjdamato, i tweaked this slightly and managed to get this working perfectly! Link to comment https://forums.phpfreaks.com/topic/136437-append-dropdown-value-to-img-src/#findComment-712920 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.